C++: Packing buffers for TCP
Folks,
I'm doing that just about everyday in Perl and it's downright easy. But what about C++ ?
The goal is to 'prepare' a buffer ready to be transmitted over TCP. For instance the buffer can have (in the right big-endian network format) :
- a command code (WORD)
- the length of the following string (LONG)
- the ASCII string, non-null terminated
In Perl we simply do:
my $test = pack("vVv", $command, $strLength, $string);
The 'v' being a word in big-endian network format, while the 'V' is a long in same format.
You get the idea.
How is it done in C/C++ ?
Thanks !
|