How to detect disconnected socket while sending data

Jun 19, 2013 at 3:18 PM
Hi Kerry,

How to detect disconnected socket while sending data using this function: void WebSocketSession.Send(string) ?
I already tried this function and it never throws exception on broken socket.

I see there is AsyncSocketSession.ProcessCompleted that throws exception and writes to error log file asynchronously if the socket connection is broken.

But I need to detect the connection without async, I have used protected override void SendSync(SendingQueue queue), bypassed from SocketSession, but it could not detect the broken connection too.

If I want to catch exception when socket is broken while sending data, can supersocket use sample code in this msdn link?
http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.connected.aspx



Regards,
Ardi
Jun 19, 2013 at 5:34 PM
There is a property named "Connected" on the session.
Jun 20, 2013 at 5:20 AM
Ok, so "Connected" property is changed when socket connection breaks.

But data-sending failure is not always caused by broken socket -- it might be due to the other node's issue. So how to detect this sending failure? As I also don't see the function WebSocketSession.Send(string) return any status?

Or let me rephrase my question: Why WebSocketSession.Send(string) does not return status? Then how do I know sending is successful or not?
Jun 20, 2013 at 6:21 AM
No, you cannot.

Even you know the exact send result, you also don't know the sent data was processed successfully and correctly by the other endpoint of the connection.

You must check it in your application layer.
Jun 20, 2013 at 12:57 PM
Could I use SocketOptionName.DontLinger = true, to immediately detect / throw exception when socket connection is broken while sending data to client ?

I my case, :
server sending data to client, and while receiving data then client turn off it's connection (wifi).
in this case, in 1 seconds, the sending data is succeed no exception.

Could SocketOptionName.DontLinger = true / timeout = 0 solved the problem ?
if yes, where could I set this option ?


Regards,
Ardi
Jun 20, 2013 at 1:27 PM
No, cannot. What's your direct requirement?

Sent from my Windows Phone

From: ardihuang
Sent: 6/20/2013 19:57
To: [email removed]
Subject: Re: How to detect disconnected socket while sending data [SuperWebSocket:447549]

From: ardihuang

Could I use SocketOptionName.DontLinger = true, to immediately detect / throw exception when socket connection is broken while sending data to client ?

I my case, :
server sending data to client, and while receiving data then client turn off it's connection (wifi).
in this case, in 1 seconds, the sending data is succeed no exception.

Could SocketOptionName.DontLinger = true / timeout = 0 solved the problem ?
if yes, where could I set this option ?


Regards,
Ardi
Jun 20, 2013 at 1:49 PM
Hi Kerry, yes sure I can check sending status in application layer.
I just wonder why WebSocketSession.Send(string) cannot detect transmission failure? Is this by design?
Because winsock Send function can indeed return error code. Aren't you actually building it on top of winsock?
Jun 20, 2013 at 2:10 PM
The sending is async and has queue support. It cannot return sending result.

Sent from my Windows Phone

From: Halim_Dreemer
Sent: 6/20/2013 20:49
To: [email removed]
Subject: Re: How to detect disconnected socket while sending data [SuperWebSocket:447549]

From: Halim_Dreemer

Hi Kerry, yes sure I can check sending status in application layer.
I just wonder why WebSocketSession.Send(string) cannot detect transmission failure? Is this by design?
Because winsock Send function can indeed return error code. Aren't you actually building it on top of winsock?
Jun 21, 2013 at 3:08 PM
I am testing using an android device to connect to superwebsocket server. Since GMS signal is intermittent here, socket disconnect is quite frequent. Need your advise if it is wise to set the TCPKeepAlive = 0 at server side to quickly detect disconnected socket? And what are the implications (if any) ?
Jun 21, 2013 at 4:52 PM
I am not sure you pass in 0, the system how to deal this case.

Change keepAliveTime and keepAliveInterval to a smaller number:
http://docs.supersocket.net/v1-5/SuperSocket-Basic-Configuration