[ENet-discuss] sending struct data

Andrew Fenn andrewfenn at gmail.com
Sun Jan 25 17:28:09 PST 2009


I've been reading through any information related to enet on if this
is possible and have decided to give up and ask on the mailing list.

typedef struct {
    char name[40];       /* Players name */
    enet_uint32 conState;  /* Connection state */
} Player;

I have the following server side code..

// enet event, data, data size, channel, priority
message(mEvent.peer,&player,sizeof(player),0,ENET_PACKET_FLAG_RELIABLE);

I have the following client side code..

Player player;
memcpy(&player, event.packet->data, sizeof(Player));
printf("Packet contains name: \"%s\" connection state: 0x%08x was
inside.\n", player.name, player.conState);

When sending and receiving the size is the same (44 bytes), however
when the data arrives player.name has garbage around the data.
(player.conState is fine).

My question is, what is the correct way of doing this?

Regards,
Andrew


More information about the ENet-discuss mailing list