473,385 Members | 1,730 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

I need a tip for socket disconnection issue.

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
2 989
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: James Yang | last post by:
Hi, I am using Sockets to connect to a remote computer and send data using Socket.Send() and receive using Socket.Receive() (block mode) . for somereason tho, when the client disconnects the...
2
by: Helmut Gardner | last post by:
Hi folks is it possible to let VB.NET call a specific handler, when a socket gets closed (either as a server, or as a client) Thank Helmut
3
by: Adam Clauss | last post by:
There seems to be various methods to determine when the remote client disconnects, but all of them I have seen are Synchronous. AKA: Right before you try to send or receive data, check. Is there...
0
by: Valerie Hough | last post by:
I have a process which accepts multiple asynchronous TCP socket connections. Periodically I want this task to check for abnormal disconnection by each client. The code that detects this correctly...
6
by: Abubakar | last post by:
Hi, lets say I have a connected SOCKET s. At some point in time, I want to know if the "s" is still valid, that it is still connected. Is there any API that I can give me this information? And...
0
by: Macca | last post by:
Hi, I am using an asynchronous socket server for my comms.I have multiple clients that connect to my server and hopefully stay connected sending data approx every 500ms. I want to make it...
3
by: xincmu | last post by:
I built a very basic server-client in C#. When my server disconnects from the client, the socket at the server is already disconnected, but the socket the client remains open. I used the sample...
11
by: atlaste | last post by:
Hi, In an attempt to create a full-blown webcrawler I've found myself writing a wrapper around the Socket class in an attempt to make it completely async, supporting timeouts and some scheduling...
3
by: Cheryl | last post by:
Hi. I am having a problem on handling asynchronous sockets in C#. I implemented a pair of client and server sockets. The connection is ok when first connected. However, when I turned off the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.