irrNetz (another lightweight enet wrapper)

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
tbw
Posts: 59
Joined: Sat Jan 15, 2011 9:51 am
Location: Germany

irrNetz (another lightweight enet wrapper)

Post by tbw »

Hello,

for my techdemo I needed some network code. BlindSide implemented irrNet and irrNetLite, so why another wrapper? The answer is very simple:
At first I wanted to get a little bit closer to game network code programming. The second reason was, I wanted to use the latest enet code (1.3.3), which comes already with compression code (range coder), so the reference to zlib is not needed any longer. Furthermore I wanted the code to be a little bit more irrLicht style.
Here is the result. At the moment there is only a simple server and a simple client sample. But I will soon add a chat sample with irrlicht gui and a game lobby sample.
My dev system is win7/MS-VisualStudio so it would be nice if someone could compile and test it on other platforms/dev systems.

http://www.van-helsing-band.de/irrlicht/irrNetz.zip
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: irrNetz (another lightweight enet wrapper)

Post by REDDemon »

very interesting. thanks for sharing
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Virion
Competition winner
Posts: 2148
Joined: Mon Dec 18, 2006 5:04 am

Re: irrNetz (another lightweight enet wrapper)

Post by Virion »

haven't have time to test this out, but it does sound interesting. good job man.
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Re: irrNetz (another lightweight enet wrapper)

Post by Midnight »

Isn't this C++ and C mixed without proper externs???
tbw
Posts: 59
Joined: Sat Jan 15, 2011 9:51 am
Location: Germany

Re: irrNetz (another lightweight enet wrapper)

Post by tbw »

Yes it is c mixed with c++, but I think the enet header (enet.h) itself ensures the proper use of "extern":

Code: Select all

...
#ifdef __cplusplus
extern "C"
{
#endif
...
so I hope that everthing is correct.
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Re: irrNetz (another lightweight enet wrapper)

Post by Midnight »

yes enet is protected, and your code is mostly correct as well (printf = c++)

but in your examples you're using _getch() and _kbhit().

Those are C if I'm not mistaken and I occasionally am. On that note I'm not trying to make a big deal of it, just thought I'd point that out in practice.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: irrNetz (another lightweight enet wrapper)

Post by hendu »

Using C from C++ code = not bad
Using Windows-only functions in examples for portable code = bad
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Re: irrNetz (another lightweight enet wrapper)

Post by Midnight »

is that what it is? Yeah we've gone down the C&Cpp debate road enuff... as a matter of fact MSDN is telling me conio and those two functions from it are proper for all versions of the C Runtime libraries so it is actually c++ anyway I guess.

At any rate I've gained knowledge from your code and I thank you for that.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: irrNetz (another lightweight enet wrapper)

Post by hendu »

MS's C runtime, not any standard. Conio is only supported on Windows (/ late DOS).
tbw
Posts: 59
Joined: Sat Jan 15, 2011 9:51 am
Location: Germany

Re: irrNetz (another lightweight enet wrapper)

Post by tbw »

Yeah, I didn't realize that conio is msvc only.
Replacing

Code: Select all

while(!(_kbhit() && _getch()=='q') && peer->getState() == net::ECS_CONNECTED)
with

Code: Select all

while(peer->getState() == net::ECS_CONNECTED)
should do fine.
The problem I ran into was the generation of memory leaks when terminating the program because the final drop statements for objects were not reached...

EDIT:
on the server side the while statement should look like this:

Code: Select all

while(1)
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Re: irrNetz (another lightweight enet wrapper)

Post by Midnight »

Ideally you could mix it with some irrlicht like demo, using irrlicht events for keys. this is (IRR)netz afterall.
Post Reply