On Wed, 09 Apr 2008 15:03:38 -0700, parez <ps*****@gmail.comwrote:
When does the socket (server) know when to stop reading.
e.g.
if i have a buffer = 25K
and do networkStream.write twice.. what will the server read? 25k or
50K?
If you write 50K, the server will eventually read 50K. However, there is
no way to predict in advance how the server will read that 50K. It could
read a single byte 50 thousand times, it could read 5 bytes ten thousand
times, it could read 50K once, it could read 10K, 10K, 25K, then 5K, it
could...
Any possible permutation is possible.
And should i send a message length for every message i send? and make
the server read specified number of bytes?
With TCP (which is what NetworkStream implies), you _must_ provide some
mechanism to allow the recipient to know how long the transmission is.
In the simplest case, the transmission is "complete" when the connection
is closed. For some protocols, that's sufficient. For higher-performance
protocols, where you want to leave the connection open between your
logical messages, you need to incorporate some means of delimiting
messages. Preceding each logical message with a byte count is indeed a
legitimate and common way to accomplish that.
Pete