Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#Actualsamoth

Posted 11 February 2013 - 11:29 AM

If your event structure does not contain any pointers, and if your software does not need to be endian-portable (e.g. client runs on x86 and server runs on PPC), and if you use the same layout/padding options when compiling (and assuming trivial constructors/destructors, likely the case here) then you can usually just copy sizeof(event) bytes from an event's address to your packet.

In every other case, see the previous answer ("serialization"). Implementations that are well-tested and work for many people are msgpack and protocol buffers (with slightly different features and overhead).

Note: If you run your own serialization, be sure to also include at least a "protocol version" when your client connects, even if you'll never going to need it. In case you do need to change something later, you avoid one big nightmare.

#1samoth

Posted 11 February 2013 - 11:26 AM

If your event structure does not contain any pointers, and if your software does not need to be endian-portable (e.g. client runs on x86 and server runs on PPC), and if you use the same layout/padding options when compiling (and assuming trivial constructors/destructors, likely the case here) then you can usually just copy sizeof(event) bytes from an event's address to your packet.

In every other case, see the previous answer ("serialization"). Implementations that are well-tested and work for many people are msgpack and protocol buffers (with slightly different features and overhead).

PARTNERS