Jump to content
  • Advertisement
Sign in to follow this  
ImperfectFreak

HawkNL and sending and reading data

This topic is 5051 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

Advertisement
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;
++ptr;
}
::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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!