Datagram question

I’ve been having trouble with Datagram. I’m using it to pack packets with enet (i.e. not using Panda sockets). As a test I just added a Datagram that has a uint32 added. Then in the server code I extract the Datagram and uint32 using the DatagramIterator. However, although the hex dump is identical for the datagram on both machines, when calling get_uint32() the value is different.

In the client:

Datagram data;
ENetPacket* packet = enet_packet_create(&data,sizeof(data),ENET_PACKET_FLAG_UNSEQUENCED);
enet_peer_send(peer_, 0, packet);

In the server:

Datagram data(event.packet->data,sizeof(event.packet->data));
DatagramIterator iter(data);
PN_uint32 protocolHash = iter.get_uint32();

I wondered if anyone had any ideas. Other than trying it with Panda sockets. I can send a struct through with no problem. I’m pretty sure I had this same issue with the Panda socket API as well though, so maybe I’m doing something weird.


Which OS are you using on the machines? If you use Mac OS on the server and Windows on the client for example, the integer layouts are different (Little Endian vs Big Endian). You should pack your values with the same endian, otherwise this problem can occur. See, too.

If this does not help, try starting the client and the server on the same machine and see if the issue persists.

I was using Windows 7 for the client and Windows 8.1 for the Server. I’m on the same machine now. Having looked a bit closer it seems the hex data dump I’m receiving is larger and different, but the data size is the same, so I’m a bit stumped by that at the moment. I thought using the Datagram would work ok, but maybe I need to do proper serialization.


Using two machines again, the data I send and receive is the same but the data is being changed when I extract it from packet->data, even on the client before I send the packet:

Datagram data
DatagramIterator iter(data);
PN_uint32 protocolHash = iter.get_uint32(); //value is correct

EnetPacket* packet = enet_packet_create(&data,sizeof(data),ENET_PACKET_FLAG_UNSEQUENCED);
Datagram data2(packet->data,sizeof(packet-data));
DatagramIterator iter2(data2);
PN_uint32 protocolHash2 = iter2.get_uint32(); //value changes

So I’ll look into that, maybe I need to cast or something. The enet mailing list is a better place to annoy people about it.