J
John Mott
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
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