My tcpclient does not recognize dropped network status.


May 23, 2012
I have a service that uses the tcpClient to send and receive data. I can unplug the network cable and the service does not know the connection has been broken. This is the code that is used to test the connection. The call to send does not throw an error. How can I get my service to know the connection has broken? Any help is greatly appreciated.

Private Function IsConnected() As Boolean
SyncLock (_sendSyncObject)
If Not _tcpClient Is Nothing Then
If IsConnectionInCloseWait() Then Return False
Dim data(0) as byte
_tcpClient.Client.Blocking = False
_tcpClient.Client.Send(data, 0, 0)
Return True
Catch ex As SocketException
If ex.NativeErrorCode.Equals(10035) Then Return True
Catch e As Exception
Return False
If Not _tcpClient Is Nothing AndAlso Not _tcpClient.Client Is Nothing Then _tcpClient.Client.Blocking = True
End Try
End If
End SyncLock
Return False
End Function
Top Bottom