Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / .NET SDK / May 2007

Tip: Looking for answers? Try searching our database.

NetworkStream.Read return 0 bytes when timeout is INFINITE

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jeevaka - 15 May 2007 19:58 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.