Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Try

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

' 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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...