Results 1 to 3 of 3
how to send a structure with different data types using udp socket ? ? i am trying to send an ATM cell which has header fields and data using udp ...
- 02-05-2010 #1Just Joined!
- Join Date
- Feb 2010
- Posts
- 2
send structure using socket
how to send a structure with different data types using udp socket ? ? i am trying to send an ATM cell which has header fields and data using udp socket and receive it on server .
- 02-05-2010 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
The problem with sending binary data structures over the network is manifold:
1. You don't know if the structure is compatible with the hardware/software on the other end (word sizes, structure padding/alignment, word endianess, etc).
2. Because of #1, you need to encode the structure to some network-neutral format when it's sent and decode it on the receiving end.
3. There are many means to accomplish #2, including XML (verbose, but human-readable).
You can eliminate this cruft if you are 100% certain that the sending and receiving ends are 100% binary compatible and that the applications were built on both ends with the same compiler and linker settings. Good luck in that!
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 02-06-2010 #3Just Joined!
- Join Date
- Aug 2007
- Posts
- 7
What you should do is serialize the information in the structure into a generic format, send that over the network, and recreate the object on the other side.
Trying to do the equivalent of a memcpy of the struct over a socket will probably fail horribly.
I suggest serializing to XML. There's lots of libraries available to work with it.


Reply With Quote