[Nel] newbies about packet schema
Kenneth Duda
kjd@cs.stanford.edu
Sat, 3 Mar 2001 02:02:34 -0800
> I have read artice for winsock program, if folling article is
> true, that snow ball netowrk driver , should change it's packet
> schema. any one can give me suggect ?
I am not familiar with the snowball protocol ("packet schema").
However, I assure you that the article is correct --- attempting
to turn TCP from a byte stream into a sequenced message stream by
disabling Nagle will not work. The only way to implement message
semantics on top of TCP is to add your own packetization to the
byte stream. For example,
void SendMessage( int socket, const void * buf, size_t length )
{
long l = htonl( length );
write( socket, &l, 4 );
write( socket, buf, length );
}
void RecvMessage( int socket, void * buf, size_t * length )
{
long l;
read( socket, &l, 4 );
l = ntohl( l );
assert( l < *length );
*length = l;
read( socket, buf, length );
}
-Ken
Kenneth J. Duda
Stanford University Distributed Systems Group
<kjd@cs.stanford.edu>