I want to send a structure which contains several double data type elements using network socket. Receivers can be of different architecture. What will be better optimized approach to do this except converting it to a string?
1 Answer
On a socket connection exists nothing but raw bytes. So you have to do two things:
Convert your double into bytes in a way the receiver can understand. This is rather complicated for doubles see here
Invent some field separator which you send between the individual doubles.
After all it is a bad idea to reinvent the wheel. You could use some established format like XML or JSON.
connect()orbind()depending on whether it's the client or the server socket, and the useread()andwrite(), but be careful with endianness.doubleyou need to take care of more issues than just endianness. Some info here: stackoverflow.com/questions/6084279/host-to-network-double