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?
Asked
Active
Viewed 1,495 times
2
-
You open a socket, call `connect()` or `bind()` depending on whether it's the client or the server socket, and the use `read()` and `write()`, but be careful with endianness. – Iharob Al Asimi Mar 25 '15 at 13:03
-
1When sending `double` you need to take care of more issues than just endianness. Some info here: http://stackoverflow.com/questions/6084279/host-to-network-double – Giorgi Moniava Mar 25 '15 at 13:12
-
As @DrKoch recommended, JSON or something similar is worth looking into. – user5071535 Jul 20 '15 at 22:45
1 Answers
1
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.