I have code similar to below:
myTcpClient.GetStream().ReadTimeout = Timeout.Infinite;
int readLength = myTcpClient.GetStream().Read(buffer, 0, expectedLength);
where myTcpClient is a TcpClient instance that is connected to a server. I
expect this to either return a number > 0 or throw an exception and it works
like that for months. But once in a while, when the system is busy, this
returns 0. (I.e. return without reading anything.) Could this be a bug in the
.NET socket API?
Rick Strahl [MVP] - 17 May 2007 08:44 GMT
If the stream is at the end you might see this. You could have a situation
where the stream contains no data...
+++Rick ---

Signature
Rick Strahl
West Wind Technologies
www.west-wind.com/weblog
>I have code similar to below:
>
[quoted text clipped - 8 lines]
> the
> .NET socket API?
Jeevaka - 17 May 2007 14:35 GMT
Hi Rick,
By 'stream is at the end' do you mean there is no data in the stream or that
the other end is closed? If you mean 'no data' shouldn't it block till there
is data rather than timeout? Extract from documentation for 'ReadTimeout':
"The default value, Infinite, specifies that the read operation does not time
out.". In this case the other end is not closed.
I reported this as a bug to MS and they got back telling it is not
reproduceable. Of course it happens only rarely. It seems at least they agree
that the behaviour is not expected.
Thanks