Posted: Fri May 11, 2007 11:40 pm
To be honest I haven't tried IrrNet yet but already used Enet a little bit some time ago. Here's what I did to send/receive my class objects (packets). Maybe it will help you some way.
It may sound a little bit "quick and dirty" but worked quite well and never had any problems with it.
I created a base class with an attribute "packettype" and a method "process" - or however you want to call them.
Now for each packet type (i.e. loginrequest, loginresponse, etc) I derivated a new class from this base class and set packettype to a unique value within its constructor.
To send a packet, I just sent the memory range where the object resided (with the correct length).
Once received I first casted the received data to the base class to read the "packettype" attribute. Once I got this, I casted the packet to its real class and called the "process" method. Done.
It may sound a little bit "quick and dirty" but worked quite well and never had any problems with it.
I created a base class with an attribute "packettype" and a method "process" - or however you want to call them.
Now for each packet type (i.e. loginrequest, loginresponse, etc) I derivated a new class from this base class and set packettype to a unique value within its constructor.
To send a packet, I just sent the memory range where the object resided (with the correct length).
Once received I first casted the received data to the base class to read the "packettype" attribute. Once I got this, I casted the packet to its real class and called the "process" method. Done.