dnbowen
August 11th, 2002, 04:03 PM
I have a point to point socket connection created. Each end is a TcpClient with an associated BinaryReader, and a BinaryWriter (for bi-directional communication).
My problem is that I need to distinguish, while receiving data, the difference between a timeout because the other end did not send the data; and a broken connection timeout (the side that would be the sender is gone.)
In both cases, a System.IO.IOException is thrown, with an InnerException of type SocketException. When I look at the ErrorCode property of the SocketException, in both cases the error is 10060. (Timeout)
I see in the Socket class , there is a public Connected property, which may give me some clue on whether or not the connection is alive, but I can not get to it directly through TcpClient.Client method, because it is protected (and I would like to avoid creating a new class which inherits the TcpClient if I can help it.)
How can I tell if the sending TcpClient is alive or dead?
My problem is that I need to distinguish, while receiving data, the difference between a timeout because the other end did not send the data; and a broken connection timeout (the side that would be the sender is gone.)
In both cases, a System.IO.IOException is thrown, with an InnerException of type SocketException. When I look at the ErrorCode property of the SocketException, in both cases the error is 10060. (Timeout)
I see in the Socket class , there is a public Connected property, which may give me some clue on whether or not the connection is alive, but I can not get to it directly through TcpClient.Client method, because it is protected (and I would like to avoid creating a new class which inherits the TcpClient if I can help it.)
How can I tell if the sending TcpClient is alive or dead?