How do I send [this] over a socket?



How do I send [this] over a socket?..

Answer / 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

More Unix Socket Programming Interview Questions

How can I tell when a socket is closed on the other end?

0 Answers  


What is a socket set used for?

0 Answers  


How come select says there is data, but read returns zero?

1 Answers  


What is sae socket?

0 Answers  


What are Sockets?

1 Answers  






What exactly does SO_REUSEADDR do?

1 Answers  


Are unix sockets faster than tcp?

0 Answers  


What's the difference between a socket and a port?

0 Answers  


How is a socket created?

0 Answers  


Is there any advantage to handling the signal, rather than just ignoring it and checking for the EPIPE error? Are there any useful parameters passed to the signal catching function?

0 Answers  


What is LILO?

2 Answers  


Why do I get EPROTO from read()?

0 Answers  


Categories