Home All Groups Group Topic Archive Search About

Detect TcpClient Connection dropped

Author
3 Aug 2006 6:29 AM
Jck
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

Author
3 Aug 2006 12:47 PM
Rob Panosh
Jck,

A few years back I had the same issues.  I never found a workaround
with 1.0/1.1 framework.  I ended up using 3rd party tool
www.genuinechannels.com for my TcpClient.

Cheers,
Rob Panosh

Jck wrote:
Show quoteHide quote
> 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
Author
3 Aug 2006 2:25 PM
iwdu15
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
--
-iwdu15