PDA

View Full Version : ENET for pascal



{MSX}
30-08-2007, 06:41 AM
Hello! Anyone managed to use ENET on pascal?
The problem is, they just give you the C sources, but not a library (dll or so). So it's not just like translating the headers..

What should one do here? Maybe compiling it and use the .o objects, linking them to the pascal executable?

http://enet.cubik.org/

Thanks :)

Setharian
30-08-2007, 08:23 AM
How about using a C/C++ compiler to first build the library and then link to it like a normal dll/so?

{MSX}
30-08-2007, 08:27 AM
uhm it's possible. I don't have so much C compiler experience as to build an SO in linux.. And i don't have a windows C compiler :P
If anybody have hints on this (maybe how to build an SO), it would be great :)

dmantione
30-08-2007, 08:29 AM
I prefer translating such code into Pascal, because then you can take advantage of FPC's system independend socket interface, allowing great portability.

Of course, this might be too much work. In such case, translating the headers is the best option. Instead of linking to a library you link the .o files (use $l instead of $linklib).

{MSX}
30-08-2007, 09:12 AM
i managed to complile the sources. I obtained some .o files, and a libenet.a:

host.o
list.o
memory.o
packet.o
peer.o
protocol.o
unix.o
win32.o
libenet.a

the libenet.a looks promising.. is it possible to obtain a libenet.so from it? or use it directly?

Btw, what's the difference between a .a and a .so file?

dmantione
30-08-2007, 12:24 PM
Simply use the .a, for the compiler .a or .so is the same.

A .a is a compile time loaded library, a .so is a runtime loaded library.

{MSX}
30-08-2007, 12:31 PM
ah ok! i'll try at home this evening.
Btw i found this two sites in google cache:

This one (http://64.233.183.104/search?q=cache:0cr7vTFfPG4J:cc.codegear.com/Item/24707+enet.pas&hl=it&ct=clnk&cd=2&gl=it&client=firefox-a) and this one (http://64.233.183.104/search?q=cache:lXH_YrFSojAJ:codecentral.borland.co m/Item/24703+enet.pas&hl=it&ct=clnk&cd=3&gl=it&client=firefox-a).

It looks like someone have already made an header, since the packages list contains:

enet.dll
enet.pas
enet_dyna.pas
enet_nocrc.dll

It should be great if i could save writing the headers, but codecentral looks not reachable for me ("Server too busy" they're on .NET framework.. How sad)

Anyone can reach it or have another link?

{MSX}
30-08-2007, 01:26 PM
nevermind, i found the package here:
http://www.codeway.co.kr/board/bbs/board.php?bo_table=Delphi_PDS&wr_id=302

i'll try asap

(ok, i'm spamming a little :P)

{MSX}
30-08-2007, 05:16 PM
ok, tested! the package works perfectly on windows, so the headers are ok!

the problem is on linux: when linking the program, it can't find the functions becouse of the name they have, with a "_" at the beginning

function enet_initialize : integer; cdecl; external enetdll name '_enet_initialize';

if i change it to:

function enet_initialize : integer; cdecl; external enetdll name 'enet_initialize';

it works!
What can it be? Maybe the functions on the DLL are named differently than on the .a library ?

Almindor
31-08-2007, 03:50 PM
Perhaps name mangling...

arthurprs
31-08-2007, 04:26 PM
What are the advantages of this lib ?

{MSX}
01-09-2007, 10:37 PM
What are the advantages of this lib ?

Well, it's cross platform for a start.
Then, it uses UDP for its low latency, but it keep packets ordered (something UDP base doesnt do).
It also have a per-packet reliable flag, so that flagged packets will be resent until they arrive to destination (just like tcp, but with single packets). In this way you can flag important packets (for example, a new player entering the game), and don't flag other packets ( for example, a player movement: even if one is lost, the next one will update the char).
It also have channels: you can assign a different channel to each packet: they'll end up in different queues. Reliable packets that are delaing a channel won't affect other channels.
It also have some integrated feature like automatic ping, bandwidth throttle, count of packet loss, and much more.

arthurprs
01-09-2007, 10:40 PM
What are the advantages of this lib ?

Well, it's cross platform for a start.
Then, it uses UDP for its low latency, but it keep packets ordered (something UDP base doesnt do).
It also have a per-packet reliable flag, so that flagged packets will be resent until they arrive to destination (just like tcp, but with single packets). In this way you can flag important packets (for example, a new player entering the game), and don't flag other packets ( for example, a player movement: even if one is lost, the next one will update the char).
It also have channels: you can assign a different channel to each packet: they'll end up in different queues. Reliable packets that are delaing a channel won't affect other channels.
It also have some integrated feature like automatic ping, bandwidth throttle, count of packet loss, and much more.

Incredible

Downloading :!:

{MSX}
02-09-2007, 08:56 PM
btw, the real site looks like being this one:

http://enet.bespin.org

It has version 1.1, the other is 1.0.
I wonder why none of the two says which one is the good one..

vgo
03-09-2007, 06:08 PM
Looks like the perfect network library for my use. I started writing a test program and quickly ran into problems with server initialization.


var
EAddress: ENetAddress;
EServer: pENetHost;
FHost: String;
FPort: Word;
FMaxConnections: LongWord;
FInboundBandwidth: LongWord;
FOutboundBandwidth: LongWord;

EAddress.host := ENET_HOST_ANY;
EAddress.port := FPort;
EServer := enet_host_create(@EAddress, FMaxConnections, FInboundBandwidth, FOutboundBandwidth);


I get "Abnormal program termination".

However, when I change the enet_host_create to this:

EServer := enet_host_create(@EAddress, 32, 0, 0);


it works... What's wrong with passing the parameters? The parameters to the function are defined as LongWords in the wrapper.

EDIT: Nevermind... I had left one of the parameters uninitialized, doh! :D

{MSX}
04-09-2007, 08:25 AM
EDIT: Nevermind... I had left one of the parameters uninitialized, doh! :D

Lol :)

Yes it's perfect for online games.. I've struggled with sockets, indy, tcp and udp for ages.. Networking looks easy at firsts, but when you get down coding, it turns out to be a pain in the ass, especially if you want portable code.

Now i've managed to compile a pascal example for Enet on Windows, Linux and even on an ARM machine!
And it's very easy to use :)

If i have some spare time i'd like to create a better package, with a crossplatform version of enet.pas and some examples.

Parcel
05-09-2007, 06:08 AM
I recently translate enet to pascal.

http://cc.codegear.com/Item/24981

It can help you. :D

vgo
05-09-2007, 06:51 AM
Wow, that's great job indeed! :)

Gonna try to compile it later today.

{MSX}
05-09-2007, 07:37 AM
I recently translate enet to pascal.

http://cc.codegear.com/Item/24981

It can help you. :D

So you're the author of the wrappers too? Very good job :)

Anyway i'm not so sure that translating the whole library is a good idea.. what if they release a new version?
Also, i don't like some of the requirements listed in readme_enetpas.txt (which doesn't mean you didn't a great work translating)

Btw, is it you who compiled enet.dll found this package (http://cc.codegear.com/Item/24707)? Maybe you have some clue about why identifiers start with an underscore?

Parcel
05-09-2007, 09:00 AM
I recently translate enet to pascal.

http://cc.codegear.com/Item/24981

It can help you. :D

So you're the author of the wrappers too? Very good job :)

Anyway i'm not so sure that translating the whole library is a good idea.. what if they release a new version?
Also, i don't like some of the requirements listed in readme_enetpas.txt (which doesn't mean you didn't a great work translating)

Btw, is it you who compiled enet.dll found this package (http://cc.codegear.com/Item/24707)? Maybe you have some clue about why identifiers start with an underscore?

Yes, I'm.

If a new version, I apply it again.

I think current version is rocksolid.

this translation is no problem in my test, but not fully tested in public.

Is underscored identifiers bad idea?

{MSX}
05-09-2007, 10:11 AM
Yes, I'm.

If a new version, I apply it again.

I think current version is rocksolid.

this translation is no problem in my test, but not fully tested in public.

Is underscored identifiers bad idea?

i dont' mean underscores in general, i mean the one on the dll. In there names start with an underscore (in red):

function enet_initialize : integer; cdecl; external enetdll name '_enet_initialize';

I don't know if that's an artifact of compiling a dll or if someone changed it or whatever else :)

The problem is that when i tried to make your headers cross platform, it turned out that libenet.a (in linux) doesn't have the underscores.
This mean i have to do something like:

{$IFDEF linux}
const PREFIX = '';
{$ELSE}
const PREFIX = '_';
{$ENDIF}
function enet_initialize : integer; cdecl; external enetdll name PREFIX+'enet_initialize';

which is not very nice.

Parcel
05-09-2007, 10:19 AM
Yes, I'm.

If a new version, I apply it again.

I think current version is rocksolid.

this translation is no problem in my test, but not fully tested in public.

Is underscored identifiers bad idea?

i dont' mean underscores in general, i mean the one on the dll. In there names start with an underscore (in red):

function enet_initialize : integer; cdecl; external enetdll name '_enet_initialize';

I don't know if that's an artifact of compiling a dll or if someone changed it or whatever else :)

The problem is that when i tried to make your headers cross platform, it turned out that libenet.a (in linux) doesn't have the underscores.
This mean i have to do something like:

{$IFDEF linux}
const PREFIX = '';
{$ELSE}
const PREFIX = '_';
{$ENDIF}
function enet_initialize : integer; cdecl; external enetdll name PREFIX+'enet_initialize';

which is not very nice.

ah, I read first page post lately.

If you trouble with underscore, change with this make file.

[quote]
BPATH=$(MAKEDIR)
INCLUDEPATH=$(BPATH)\..\include
LIBPATH=$(BPATH)\..\lib

CC=$(BPATH)\bcc32
RC=$(BPATH)\brcc32
]

If you don't want CRC check, remove '-DUSE_CRC32'.

Traveler
11-04-2008, 12:07 PM
Sorry for reviving this somewhat old thread, but I just found out about this unit, and I was wondering if someone could post some working sample code. I already found http://www.afterwarp.net/forum/thread1274.html this sample, but I can't seem to get it to work. The server sample wont compile due to some error in onethread.start (my version apparently requires additional parameters) and the client sample assumes a combobox of which I'm not certain what values I need to fill it with.


Thanks

technomage
11-04-2008, 04:17 PM
I just found this thread too, I've downloaded the sample and I'll see if I can get it to work :)

Parcel
13-04-2008, 03:25 AM
http://www.mediafire.com/?5x1zcvxexda

It has some new and simple example.

technomage
13-04-2008, 02:08 PM
I'm having trouble getting a shared object (or a DLL) out of the projects provided. Anyone got any tips, I'm trying to get the .so under linux and I'm afraid I'm a bit rusty in this area :).


Also does someone have an updated cross platform header for this library?

Andreaz
13-04-2008, 08:03 PM
Sorry for reviving this somewhat old thread, but I just found out about this unit, and I was wondering if someone could post some working sample code. I already found http://www.afterwarp.net/forum/thread1274.html this sample, but I can't seem to get it to work. The server sample wont compile due to some error in onethread.start (my version apparently requires additional parameters) and the client sample assumes a combobox of which I'm not certain what values I need to fill it with.


Thanks

Here's a working demo i wrote to get familliar with ENet for my current project

http://www.phoenixlib.net/files/EnetDelphi.rar

Traveler
14-04-2008, 09:03 AM
Wow, this awesome. Thanks a lot Andreaz, and you as well Parcel! :D

Btw, how's it going Andreaz? We haven't heard from you in a while. Still working on PhoenixLib? You might be interested to know that I'm using it to recreate Village Defense. Things have been a bit quiet on my website for a long while, but that has changed in the last month. I've posted some updates along with some screenshots and a video.

Anyway, If you have a few spare minutes, let us know, I'm sure more than a few of us are interested to know. :)

Andreaz
14-04-2008, 03:30 PM
Well, what can i say, life's been busy :)

The work on phoenix is progressing, not as fast as i would like but there's alot of stuff happening in the shadows :)

Doing a big rewrite of many of the parts of the lib, for greater speed and more features.

The next version will support 3D rendering and alot of other features, i'm adding a native texture format that loads 260% faster then the freeimage loading code.

Also coded a model loader with support for gpu based skinning and alot of supporter classes for 3D rendering including camera support and shaders.

The list of changes is huge and the ones listed abowe is just a small part, I'm working on a 2D in 3D game as a platform for the development of Phoenix, wich helps in getting the library into a more solid state.

Great to hear about the village defence project, give me a tell if you need some help, your projects has always been a great inspiration to me.

technomage
14-04-2008, 04:48 PM
I got this working under Linux :). It seems nice and quick. I'll post the code of the simple command line demos when I get a moment.

next stop get it working on Windows and OS X :D.

I think we need a single place to store the interface unit to the dll. Perhaps we need to contribute a unit to free pascal.

I'm not using the transalated code at the moment, as the library is now verison 1.2 I'm not sure what version the translation is.