I need a tip for socket disconnection issue.

  • Thread starter Thread starter Marty
  • Start date Start date
M

Marty

Hi,

I have a server that handle many client connection. In the case that
the server try to send a message to a client.

When the server is doing the mySocket.send(myMessage) and the client
connection is already broken, what is the best way to handle this?

Exception raising cost very much in time, does catching only like this
code sample is doing is good?

''''''''''''''''''''
Try
If (Not mySocket Is Nothing) Then
If (mySocket.Connected) Then
mySocket.Send(myMessage)
End If
End If

Catch
'do something
End Try
''''''''''''''''''''

In this case, the "mySocket.Connected" does not detect that the
connection is not good between client and server and it still try to send.

Thanks
Marty
 
i'm only doing irc chat similar to mirc
Public Sub Disconnect()
Try
'Kill the socket.
Client.Shutdown(SocketShutdown.Both)
'Kill any data being sent or received.
'let the functions know that we are disconnecting()
'this prevents data being sent after the socket closes
'apparently .Shutdown doesn't work as documented()
'this is the work(around)
mConnected = False
'Kill socket
Client = New Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp)
Catch : End Try
End Sub
 

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

Back
Top