Socket : can an asynchronous Receive returns without reading all the bytes I asked for?
Posted
by NorthWind
on Stack Overflow
See other posts from Stack Overflow
or by NorthWind
Published on 2009-06-09T13:13:26Z
Indexed on
2010/04/16
20:03 UTC
Read the original article
Hit count: 325
Hi;
I was reading an article on Vadym Stetsiak's blog about how to transfer variable length messages with async sockets (url: http://vadmyst.blogspot.com/2008/03/part-2-how-to-transfer-fixed-sized-data.html).
He says :
What to expect when multiple messages arrive at the server? While dealing with multiple messages one has to remember that receive operation can return arbitrary number of bytes being read from the net. Typically that size is from 0 to specified buffer length in the Receive or BeginReceive methods.
So, even if I tell BeginReceive to read 100 bytes, it may read less than that and returns??? I am developing a network-enabled software (TCP/IP), and I always receive the same exact number of bytes I asked for.
I don't even understand the logic : why would Receive completes asynchronously if it didn't get every byte I asked for ... just keep waiting.
Maybe it has something to do with IP vs TCP?
Thank you for your help.
© Stack Overflow or respective owner