Jump to content
  • Advertisement
Sign in to follow this  

HawkNL and sending and reading data

This topic is 5129 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Assuming that each string is <= 255 characters, and there's <= 255 strings, I'd do something like:

template< class Iter >
void sendArray( Iter ptr, Iter end, SOCKET s ) {
static unsigned char tempBuf[65536];
unsigned char * buf = tempBuf;
assert( end-ptr <= 255 );
*buf++ = (unsigned char)(end-ptr);
while( ptr < end ) {
size_t l = (*ptr).size();
assert( l <= 255 );
*buf++ = (unsigned char)l;
strcpy( (char *)buf, (*ptr).c_str() );
buf += l;
::send( s, tempBuf, ptr-tempBuf, 0 );

To receive it, you'd read a byte for the number of strings, and then read that many strings, each of which is a length byte, followed by that many characters of data.

For the more general case (which I'm sure you'll run into pretty quickly), google for "marshalling" or "serialization".

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!