Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,


I have a Tcp CLient Application, which will connect to a Hardware Server via Ethernet Tcp/Ip for Sending and receiving data.

Now I want to check whether Connection between My Application and Server is Active or broken continuously.

I tried the following code


VB
Private Client As New TcpClient



Client.Connect(IpAddr, PortNo)



Function IsConnected() As Boolean
        IsConnected = False
        If (Client.Client.Connected) Then
            If ((Client.Client.Poll(0, SelectMode.SelectWrite)) AndAlso (Not Client.Client.Poll(0, SelectMode.SelectError))) Then
                Dim b As Byte() = New Byte(1) {}
                If Client.Client.Receive(b, SocketFlags.Peek) = 0 Then
                    Return False
                Else : Return True
                End If
            Else
                Return False
            End If
        Else
            Return False

        End If
    End Function


Above Code is giving always TRUE, even if connection is broken.

Can you guys suggest me some thing else which will work for my requirement.

Thank You
Srinivas
Posted
Comments
Maciej Los 23-Jul-14 2:01am    
http://support.microsoft.com/kb/137984
http://social.msdn.microsoft.com/Forums/en-US/d5b6ae25-eac8-4e3d-9782-53059de04628/tcp-keepalive-settings-problem?forum=netfxnetcom

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900