Detect TcpClient Connection dropped

G

Guest

Could someone tell me how to detect TcpClient connection dropped, please?

I have a TcpClient connected to a server by IP and Port. The TcpClient only
read data from the server. However, if there is no data received from the
server for a period of time, I am unable to determine whether the connection
is dropped or simply no data is sent from the server.

Work around:
Currently, I am trying to send data with 0 length to detect the connection.
But I want to have a proper way to do it. Please help!

While True
Try
myTcpClient.GetStream().Write(MySendBuffer, 0, 0)
Catch ex As Exception
' Assume connection dropped
Exit While
End Try
Application.DoEvents()
End While
 
G

Guest

i suggest using sockets for this. when one users ends the connection, your
informed in code. Also, you can check using properties to see if theres an
active connection
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top