Answer Posted / chaitanya
Anything other than single bytes of data will probably get mangled unless you take care. For integer values you can use htons() and friends, and strings are really just a bunch of single bytes, so those should be OK. Be careful not to send a pointer to a string though, since the pointer will be meaningless on another machine. If you need to send a struct, you should write sendthisstruct() and readthisstruct() functions for it that do all the work of taking the structure apart on one side, and putting it back together on the other. If you need to send floats, you may have a lot of work ahead of you. You should read RFC 1014 which is about portable ways of getting data from one machine to another (thanks to Andrew Gabriel for pointing this out).
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Can multiple clients connect to same socket?
Are sockets files?
Why does it take so long to detect that the peer died?
Can multiple sockets use the same port?
What is the purpose of socket?
What is a deep well socket?
Are unix sockets faster than tcp?
Why do I get EPROTO from read()?
Why sockets are used?
What is difference between socket and websocket?
How can I force a socket to send the data in its buffer?
Can a single socket port be used for multiple applications?
How does a socket work?
What is a socket address?
What is the difference between SO_REUSEADDR and SO_REUSEPORT?