Re: I need a tip for socket disconnection issue.



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



Marty wrote:

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
.



Relevant Pages

  • Re: Socket switch delay
    ... both at the client and at the server (and why ... would you set the send buffer size to zero on a non-overlapped ... One glaring error is your client does ... So when you use a single socket, ...
    (microsoft.public.win32.programmer.networks)
  • Re: Locking on async calls
    ... you must synchronize the entire SendMessage routine as an atomic ... operation to prevent mixed messages from being transmitted to the server. ... You are correct that read and write on the socket do not interfere with each ... If you want to handle multiple client connections from one server object ...
    (microsoft.public.dotnet.general)
  • Re: socket communication: socket doesnt connect
    ... Microsoft MVP, MCSD ... As far as your server code goes, ... accept the listening socket. ... Client client = new Client; ...
    (microsoft.public.vc.language)
  • Re: TCP server stop receiving new connections
    ... reset the event mask of your listening socket each time you ... I have a strange problem in my class library used by all our client ... server applications. ... incomming connections, but keeps current connections. ...
    (microsoft.public.win32.programmer.networks)
  • Re: Design issue with WinSock/GetQueuedCompletionStatus
    ... delegate that to a shutdown routine called after all worker threads ... The application I've created is a server accepting connections on a few ... different TCP/IP ports and then lets the client run different commands. ... a TCP/IP socket can be closed for 2 different reasons: ...
    (microsoft.public.win32.programmer.networks)

Loading