[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 731
  • Last Modified:

Problem disconnecting .NET TCP client

Hello, here's my code to disconnect a TCP client connected to a TCP server:

    Public Function Disconnect() As Boolean

        ptr_ClientSocket.Shutdown(Net.Sockets.SocketShutdown.Both)
        ptr_ClientSocket.BeginDisconnect(True, New AsyncCallback(AddressOf DisconnectCallback), Nothing)
        SetState(eState.Disconnecting)

        Return True

    End Function

    Private Sub DisconnectCallback(ByVal ar As IAsyncResult)

        ptr_ClientSocket.EndDisconnect(ar)
        SetState(eState.Ready)

    End Sub

Open in new window


The weird part is that my DisconnectCallback never fires, and it stalls in 'Disconnecting' state.  Does this require some action on the server side?  What's the right way to do this?

Thanks for any help.
0
RonMexico
Asked:
RonMexico
1 Solution
 
David Johnson, CD, MVPOwnerCommented:
clientSocket.Close()
clientSocket.Client.Dispose()

is how I deal with it also on the server you should have a sort of a heartbeat that checks the client connection status by sending 1 byte if it fails then the client is disconnected otherwise it is connected.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now