I created a server-client application using the asynchronous socket. I found the problem when closing a socket on the server, applications so closed. The procedure that I do to close the socket server is:
- Terminate the listening thread.
- Close the client socket is still connected to the server.
- Close the server socket.
How to prevent the application is closed, when I close the server socket? Thanks
Protected Friend Sub CloseServerSocket(ByVal IPAddress As IPAddress, ByVal socketPort As Integer)
' Terminate the listening thread.
If listeningThread.IsAlive Then listeningThread.Abort()
' Close the client socket is still connected to the server.
For Each sock As Socket In workSocketList
If sock.Connected Then
Interlocked.Decrement(workCount)
sock.Close()
End If
Next
' Close the server socket.
serverSocket.Close()
serverSocket = Nothing
End Sub
1 Answer