By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,694 Members | 1,320 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,694 IT Pros & Developers. It's quick & easy.

I need a tip for socket disconnection issue.

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

Nov 21 '05 #2

P: n/a
Thanks Supra :)
I'll test it with the shutdown.
Marty

Supra wrote:
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

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.