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 / New Users / July 2007

Tip: Looking for answers? Try searching our database.

tcpclient in .net 2.0

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Keith Langer - 06 Jul 2007 19:55 GMT
Maybe someone has come across this situation and has a way to handle
it.

If I have a tcpClient object  and do a GetStream.Read on it after
setting a ReceiveTimeout, I'm getting different behavior in .Net 2.0
than in 1.0 when the method returns 0 bytes (which signifies a
timeout).  In both cases I get a System.IO.IOException , but in the
2.0 framework the socket also disconnects when this occurs (in 1.0 it
did not disconnect).  They have made some improvements in the
tcpClient class, such as exposing the underlying socket, so I'd prefer
to keep using tcpClients.  Any idea how I can prevent this
disconnect?  Right now I'm checking DataAvailable and using
Thread.Sleep as a workaround, but I'd prefer to do a blocking read
call.

Thanks,
Keith
Peter Duniho - 06 Jul 2007 20:57 GMT
> [...]  In both cases I get a System.IO.IOException , but in the
> 2.0 framework the socket also disconnects when this occurs (in 1.0 it
> did not disconnect).  They have made some improvements in the
> tcpClient class, such as exposing the underlying socket, so I'd prefer
> to keep using tcpClients.  Any idea how I can prevent this
> disconnect?

I don't know how they implement the timeout, but assuming they use the  
underlying socket timeout, then there's a good reason for disconnecting  
the socket after a timeout, as the socket is in an indeterminate state at  
that point.

So, it's likely that this change in behavior is actually a usability  
bug-fix, so that inexperienced socket programmers don't go trying to  
continue to use a socket on which a timeout has occurred.

Note that this receive timeout is different from using a timeout in other  
methods (e.g. Socket.Select()).  You can implement a timeout in a variety  
of other ways that don't invalidate the socket.  But the ReceiveTimeout  
property likely sets the socket's receive timeout option directly  
(setsockopt(...SO_RCVTIMEO..)), and that's what will invalidate the socket.

Pete

Rate this thread:







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.