[ENet-discuss] sending struct data

Andrew Fenn andrewfenn at gmail.com
Mon Jan 26 06:42:07 PST 2009


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 <little.coding.fox at gmail.com> 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 <andrewfenn at gmail.com> 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
>> ENet-discuss at cubik.org
>> http://lists.cubik.org/mailman/listinfo/enet-discuss
>
>
> _______________________________________________
> ENet-discuss mailing list
> ENet-discuss at cubik.org
> http://lists.cubik.org/mailman/listinfo/enet-discuss
>
>


More information about the ENet-discuss mailing list