2

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?

3
  • 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. Commented Mar 25, 2015 at 13:03
  • 1
    When sending double you need to take care of more issues than just endianness. Some info here: stackoverflow.com/questions/6084279/host-to-network-double Commented Mar 25, 2015 at 13:12
  • As @DrKoch recommended, JSON or something similar is worth looking into. Commented Jul 20, 2015 at 22:45

1 Answer 1

1

On a socket connection exists nothing but raw bytes. So you have to do two things:

  1. Convert your double into bytes in a way the receiver can understand. This is rather complicated for doubles see here

  2. 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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.