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 / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

DataAvailable property in TCPClient class misleading in usage

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Mott - 23 Jul 2007 00:34 GMT
Hello,

I'm not really sure if this is the best place but I couldn't find a TCP
specific newsgroup.

It appears that the DataAvailable property of the TCPClient is just a test
for whether data is buffered, and does not take into account whether the
socket to the server is still open. While this is technically accurate, data
either is or is not buffered, its not as useful as knowing whether or not
the socket is still open or not.

The sample code in MSDN has a loop testing on DataAvailable, which will
produce a false negative if the server sends data in bursts with delays. It
is useful to know that data is buffered, but its incomplete knowledge. There
is a property on the TCPClient called 'Connected' which be tested as well.

My solution in my sample code is to use the ReadByte(), which is less
efficient but will return -1 when the socket is closed.

http://www.nicecleanexample.com/ViewSnippet.aspx?TID=dotnet_tcpclient1

Thanks,

John
bruce barker - 23 Jul 2007 18:33 GMT
http is a stream protocol over tcp/ip. there is no notification of
closed sockets or heartbeats. its a standard ack/nak protocol. when the
last data is sent, a fin is sent. if the socket is closed, nothing is
sent. the receiver detects a closed socket via a timeout. if the
connection is closed during a data packet send, the timeout is quick. if
between packet sends, then its very long.

because tcp is a reliable protocol, packets are delivered in order, and
the sender is notified of receipt, it is always buffered, as ip is not
reliable and will deliver packets out of order.

your code does not really change anything. reading the steam shoudl
return an error as quick as readbytes, which is just a read of buffer
size one. if you want more control, look at the socket library.

-- bruce (sqlwork.com)

> Hello,
>
[quoted text clipped - 20 lines]
>
> John

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.