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.
Private Function IsConnected() As Boolean SyncLock (_sendSyncObject) If Not _tcpClient Is Nothing Then Try If IsConnectionInCloseWait() Then Return False Dim data() As Byte = {} _tcpClient.Client.Blocking = False _tcpClient.Client.Send(data, 0, 0) Return True Catch ex As SocketException ' 10035 == WSAEWOULDBLOCK If ex.NativeErrorCode.Equals(10035) Then Return True Catch e As Exception Return False Finally 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