[ENet-discuss] Sending numerical values in packets
Brian Hook
hook_l at pyrogon.com
Sat Nov 8 04:59:44 PST 2003
On Sat, 08 Nov 2003 14:26:05 +0200, Mika Halttunen wrote:
> Greetings!
> I was wondering, how could I send numerical values, i.e. short
> ints, ints and floats, using ENetPackets?
First off, I'd highly advise against sending floats, especially if
you're going to have communication between different clients (e.g. a
Mac client and a PC client). At the very least, do NOT do any type of
floating point comparisons between clients.
To answer your question, you'll want to take all our data, convert it
to a standardized network byte order (e.g. big-endian), serialize,
send, and then do the opposite on the other side. You can use the
standard functions such as htons, etc. or you can roll your own.
Check out www.poshlib.org for a simple library (header + C file) that
handles endianess conversion and serialization.
Brian
More information about the ENet-discuss
mailing list