Is "strcat" the right thing? I would try "strcpy" instead. Bye Mark
-----Ursprüngliche Nachricht----- Von: [email protected] [mailto:[email protected]] Im Auftrag von Andrew Fenn Gesendet: Montag, 26. Januar 2009 15:42 An: Discussion of the ENet library Betreff: Re: [ENet-discuss] sending struct data I tried adding a terminator to the end of the char with no results. Here's the output of what I am receiving on the client.. Packet contains name: "��j�/�h�� �O\�H��'� ��� Player" connection state: 0x00000003 was inside. Here's some more code for the server... Player player; strcat(player.name, "Player"); player.conState = 0x0003; message(mEvent.peer,&player,sizeof(player),0,ENET_PACKET_FLAG_RELIABLE); bool Server::message(ENetPeer *peer,const void* msg, size_t size, enet_uint8 channel, enet_uint32 priority) { bool result = true; ENetPacket * packet = enet_packet_create (msg, size, priority); if (enet_peer_send(peer, channel, packet) <0) { result = false; } enet_host_flush(mServer); return result; } On Mon, Jan 26, 2009 at 7:46 AM, Nuno Silva <[email protected]> wrote: > The name may somehow be missing it's terminator ('\0'), check if you're > correctly sending it and if you even received it in the first place. > > On Mon, Jan 26, 2009 at 1:28 AM, Andrew Fenn <[email protected]> wrote: >> >> 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 >> _______________________________________________ >> ENet-discuss mailing list >> [email protected] >> http://lists.cubik.org/mailman/listinfo/enet-discuss > > > _______________________________________________ > ENet-discuss mailing list > [email protected] > http://lists.cubik.org/mailman/listinfo/enet-discuss > > _______________________________________________ ENet-discuss mailing list [email protected] http://lists.cubik.org/mailman/listinfo/enet-discuss _______________________________________________ ENet-discuss mailing list [email protected] http://lists.cubik.org/mailman/listinfo/enet-discuss
