Recent

Author Topic: ENet - Reliable UDP networking library  (Read 10192 times)

Black Doomer

  • Newbie
  • Posts: 3
  • Dmitry D. Chernov
    • Doom 2D - One of the best 2D platformers with amazing netgame!
ENet - Reliable UDP networking library
« on: March 26, 2015, 11:26:42 am »
ENet - Reliable UDP networking library

Official website

Shortcut of it's features list:
  • Own socket system over UDP like Berkley sockets.
  • Packets could be sent both in reliable and unreliable modes through the same socket.
  • All packets are right-ordered, regardless of reliability, but an ability to send unsequenced packets like pure UDP is also here.
  • Channels, the feature that is really awesome. Read this as "independently ordering sequences of packets".
  • It provides REALLY FAST networking without any serious latencies on large pings, and at the same time it is very easy to use.

In summary, ENet provides you to fast reliable protocol that is between UDP and TCP and have the best features from both of them.
You can read more detailed information at ENet website, for example: features list or brief tutorial.

Here you can download translated ENet headers to use it with FreePascal.

At beginning, I translated ENet library headers for Delphi 7 to use it in Doom 2D: Forever (if you're interested, you can take them here at project GitHub). After that, I've decided to adapt them for FreePascal due to small amount of changes to perform that. So, here they comes.

https://github.com/cher-nov/enet-fpc

Hope that this will be useful for someone. Any feedback and criticism are also welcome.
« Last Edit: July 29, 2017, 08:45:34 pm by Black Doomer »

JZS

  • Full Member
  • ***
  • Posts: 194
Re: ENet - Reliable UDP networking library
« Reply #1 on: March 26, 2015, 12:24:22 pm »
Good efforts. I will try it. Thanks for sharing it.
I use recent stable release

parcel

  • Full Member
  • ***
  • Posts: 143
Re: ENet - Reliable UDP networking library
« Reply #2 on: April 16, 2015, 07:15:18 am »
I converted old enet to pascal source.  :-[

https://github.com/rasberryrabbit/enet-freepascal


MvC

  • New Member
  • *
  • Posts: 25
    • Free Pascal Core team member
Re: ENet - Reliable UDP networking library
« Reply #3 on: April 18, 2015, 01:14:32 pm »
I added the headers, but removed all _ from unit names, and changed the extension to .pp

I also added a slightly adapted version of the class that can be found in
https://github.com/rasberryrabbit/enet-freepascal

I additionally created some example command-line client and server apps that demonstrate how to use this class.

All was tested on linux and found to work correctly.

hallenberger

  • New Member
  • *
  • Posts: 43
Re: ENet - Reliable UDP networking library
« Reply #4 on: April 18, 2015, 02:19:24 pm »
Where is "INVALID_SOCKET" defined on linux/fpc?
Debian/Sparky Linux
OS: Windows XP
Lazarus: with fpcupdeluxe

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: ENet - Reliable UDP networking library
« Reply #5 on: April 18, 2015, 02:54:11 pm »
To my best knowledge that is a winsock specific identifier, so in Winsock or winsock2.

Correction, it seems not defined on linux, but is seems to be in sockets for e.g. BSDs.
« Last Edit: April 18, 2015, 02:56:55 pm by marcov »

Black Doomer

  • Newbie
  • Posts: 3
  • Dmitry D. Chernov
    • Doom 2D - One of the best 2D platformers with amazing netgame!
Re: ENet - Reliable UDP networking library
« Reply #6 on: August 02, 2016, 06:50:45 pm »
I've recently revised the translated headers and, unfortunately, found some issues.

First of all, C headers were translated directly into Pascal modules (units), but, as it's generally known, they're quite different things. This happened because Pascal was a fairly new language for me, so I misunderstood some of it basic principles. Because of this, I decided to merge all units into one module.

Secondly, original ENet headers aren't separated into external (API) and internal parts, so I automatically translated some structure definitions that aren't needed for DLL usage. I've removed them from the revised version.

And thirdly, when C enum is just a simple grouping type so you can use its constants as they were simply macro definitions, this doesn't apply to Free Pascal where enums are entirely separate types. So I redefined those enums which were defined only for grouping purposes, to the simple constants.

So I've uploaded new version of the headers, and updated link in the first post.

Thaddy

  • Hero Member
  • *****
  • Posts: 14213
  • Probably until I exterminate Putin.
Re: ENet - Reliable UDP networking library
« Reply #7 on: August 02, 2016, 06:58:36 pm »
And thirdly, when C enum is just a simple grouping type so you can use its constants as they were simply macro definitions, this doesn't apply to Free Pascal where enums are entirely separate types. So I redefined those enums which were defined only for grouping purposes, to the simple constants.

Actually that is not the whole story.
If you would have used h2pas to translate the headers - to some extend - you have the option in h2pas to translate C(++) enums into consts directly.
There isn't much difference and they are casteble anyway. What you write is incorrect.
An enum type in Pascal is also a simple grouping type, but a little more powerful.
But translating C enums into pascal consts is also valid and won't hurt (much).

See the h2pas documentation.

.. And ahum, why wouldn't other UDP solutions in pure pascal NOT be reliable? I mean Synapse is just as reliable (and fast!). And there are many more.

But I will run some speed and reliability tests anyway.
« Last Edit: August 02, 2016, 07:06:02 pm by Thaddy »
Specialize a type, not a var.

Black Doomer

  • Newbie
  • Posts: 3
  • Dmitry D. Chernov
    • Doom 2D - One of the best 2D platformers with amazing netgame!
Re: ENet - Reliable UDP networking library
« Reply #8 on: August 02, 2016, 07:17:04 pm »
If you would have used h2pas to translate the headers - to some extend - you have the option in h2pas to translate C(++) enums into consts directly.
There isn't much difference and they are casteble anyway. What you write is incorrect.
It was just about C-style enum usage. Of course, I can cast, and know about it.

.. And ahum, why wouldn't other UDP solutions in pure pascal NOT be reliable? I mean Synapse is just as reliable (and fast!). And there are many more.
Because pure UDP doesn't provide you any guarantees about transmission order, data correctness and consistency and other. ENet implements TCP-like protocol over UDP, but much more lightweight and optimized for real-time applications (e.g. games).
« Last Edit: August 04, 2016, 07:06:34 am by Black Doomer »

 

TinyPortal © 2005-2018