1

I have a simple question, that I can't seem to google my way to an answer!

Lets say we have two computers, that will exchange data via UDP. Now we are not talking about large amount of data, maybe about 10 numbers, and elts say 5 of them are floats and the others are regular integers.

How would one package these up variables up in one big message? Is there any standard that I could follow.

Of course I could simply say that between every variable one should have the string STOP, then the receiving computer would get int1_STOP_int2_STOP_...etc as the string, and the receiving computer will parse it to the correct values.

But this method seems very crude.

I have seen LCM (Lightweight Communications and Marshalling) that could be a good idea, but maybe its an overkill when bandwidth is not an issue.

Any suggestions are greatly appreciated!

Dammi
  • 1,268
  • 2
  • 13
  • 23
  • Are both computers running the same operating system? The same underlying hardware (most specifically CPU)? Are both programs compiled with the same compiler? If the answer to all of the previous questions is "yes" then you could pack it up in a simple `struct`. – Some programmer dude Nov 03 '16 at 14:14
  • And if the machines or compilers involved may vary in any significant way, then the safest solution is probably to serialize the numbers to strings, and pack the strings into your message. You might use a (length, content) format for the strings, a delimited format such as you described, or even fixed-length strings. – John Bollinger Nov 03 '16 at 14:23
  • The answers would be yes/no/yes in this case :) Will the hardware difference really be an issue ? – Dammi Nov 03 '16 at 14:24
  • If the CPU is different you need to be careful about [endianness](https://en.wikipedia.org/wiki/Endianness) issues. Serialization to a safe format (usually text) is probably the way to go. – Some programmer dude Nov 03 '16 at 14:30
  • Excellent, thanks for your suggestions guys! – Dammi Nov 03 '16 at 15:00
  • Note that UDP seems great until you start to implement it, then you discover that there's a reason people jump ahead to using TCP instead. Also, passing data between machines of unknown architecture is best done by sending in a more human readable format (xml for example). Unless, of course, you have one machine that is ASCII and another that is EBCDIC. In that case your life will be more difficult. – KevinDTimm Nov 03 '16 at 15:10

0 Answers0