[ENet-discuss] Sending a struct which contains a pointer toarbitrary data...

Marc Rochel marc.rochel at udicom.de
Thu Apr 2 15:07:09 PDT 2009


Hi Daniel,

enet_peer_send takes a pointer to data it should send. You can pass
pointers to structs, but it doesn't know about the struct and treats it
as flat memory. It doesn't know that something in your struct is a
pointer to data you want to transmit additionally.

So somehow you have to flatten your data to a binary string. That's what
serialization does. You have to serialize your construct of classes
representing the message you want to transmit to a plain array of bytes.

You can add, depending on the amount of different messagetypes you need,
add a byte/a few bytes at the beginning of that binary string to
differentiate between the different messages. On the sender side, you
already know the type of message you want to send, so you know what id
you have to put there. On the receiver side, you read that id and call
the corresponding unserialization code.

So in short, the functionality you are asking for here isn't provided by
ENet. That's something you have to add on your own or take from
somewhere else.

Best regards
    Marc
 

-----Original Message-----
From: enet-discuss-bounces at cubik.org
[mailto:enet-discuss-bounces at cubik.org] On Behalf Of Daniel Aquino
Sent: Donnerstag, 2. April 2009 21:00
To: Discussion of the ENet library
Subject: [ENet-discuss] Sending a struct which contains a pointer
toarbitrary data...

I currently have something similar too:

struct packet {
       enum packet_type type;
       void* data;
} packet;

I assign this to the ENetPacket->data but as you all probably know the
(void*) pointer address is sent in the packet and not the data that
the pointer reflects...

I need a method to send the "type" and different types of data...

In one instance data might reflect a char* or could be an ENetAddress
etc...

Any advice on how I should be approaching this?

Thanks!
_______________________________________________
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