R
Ryan Petrie
Hello all,
Is it possible for Socket.Available to lie -- that is, is it possible
for the following to fail?
byte[] data = new byte[socket.Available];
int bytesRead = socket.Receive(data);
Debug.Assert(bytesRead == data.Length);
It appears that's exactly what's happening for me. I'm using one
routine (=one thread) to handle multiple connections. It does a
Socket.Select() on all sockets, and then for each socket with pending
data, it reads from the socket the amount of bytes returned by
socket.Available(). It stores it in a temporary buffer until the number
of bytes I expect arrive, at which point it's deserialized and queued up
for processing by another thread.
Sometimes, though, when several small messages are coming in at a time,
less bytes are actually received (as returned by Socket.Receive()) than
Socket.Available reported just a line or two of code previously. What
gives?
Incidentally, I tried ignoring that fact and continuing on, hoping the
data would come in the next read. But unfailingly I get a
SerializationException, suggesting to me that data really was lost.
Thanks in advance,
Ryan
Is it possible for Socket.Available to lie -- that is, is it possible
for the following to fail?
byte[] data = new byte[socket.Available];
int bytesRead = socket.Receive(data);
Debug.Assert(bytesRead == data.Length);
It appears that's exactly what's happening for me. I'm using one
routine (=one thread) to handle multiple connections. It does a
Socket.Select() on all sockets, and then for each socket with pending
data, it reads from the socket the amount of bytes returned by
socket.Available(). It stores it in a temporary buffer until the number
of bytes I expect arrive, at which point it's deserialized and queued up
for processing by another thread.
Sometimes, though, when several small messages are coming in at a time,
less bytes are actually received (as returned by Socket.Receive()) than
Socket.Available reported just a line or two of code previously. What
gives?
Incidentally, I tried ignoring that fact and continuing on, hoping the
data would come in the next read. But unfailingly I get a
SerializationException, suggesting to me that data really was lost.
Thanks in advance,
Ryan