Link to home
Start Free TrialLog in
Avatar of malben
malben

asked on

C# - UDP (UdpClient) Raw Packet - Constructing data payload?

Hi,

I'm building a UDP server/client program using UdpClient in C#.
Its 'send' (byte[] , int length, IPAddress dest, int port) method allows me to send bytes to the other side.  However, what I really want to do is I want to send multiple pieces of data to the other side.  I therefore would like to have a data struture which contains the data which I would like to send and then send this data, thus I need to explicitly construct the UDP payload myself.  Therefore, the payload must be split into multiple data items to send to the other side.

I've looked over books and documentation but can't seem to find the answer?

Therefore, I was wondering how you would implement this?

Thanks in advance for your help!
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of malben
malben

ASKER

Hi,

Would be possible to use serialization with structs?

thanks
Yes you can serialize a struct. Are you not trying to make your data as small as possible for transmission over the wire? If so you should be able to use the above example.

http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/msg/b19f6b810baa3315 offers a few ready to go solutions as well.

Cheers,

Greg
Avatar of malben

ASKER

Thanks guys for your help.  I will give it a try!