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

Detecting socket disconnection (Async?)

P: n/a
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 no way to do raise an event for this? That way you know as soon as the client disconnects?

There are events for Accepting, Connecting, Receiving, Sending... why not one for disconnecting?

--
Adam Clauss
ca*****@tamu.edu
Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Adam,

There are two types of disconnects; when the client explicitly closes
the
connection or when the connection is lost due to a network error (connect
went down, etc).

When the client explicitly closes the connection, your recieve callback will
be called and your will recieve zero bytes - when this happens you know that
the client is question has disconnected. To check for network errors you
will
have to catch the SocketException which you will be getting :)

HTH,

//Andreas

"Adam Clauss" <ca*****@tamu.edu> skrev i meddelandet
news:ex**************@TK2MSFTNGP11.phx.gbl...
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 no way to do raise an event for this? That way you know as soon as the client disconnects?
There are events for Accepting, Connecting, Receiving, Sending... why not one for disconnecting?
--
Adam Clauss
ca*****@tamu.edu

Nov 16 '05 #2

P: n/a
Hmm... OnReceive gets called for OnDisconnect. Well, I suppose it works, just does not seem very logical.

Thanks!

--
Adam Clauss
ca*****@tamu.edu
"Andreas Håkansson" <andy.h (at) telia.com> wrote in message news:uw**************@TK2MSFTNGP09.phx.gbl...
Adam,

There are two types of disconnects; when the client explicitly closes
the
connection or when the connection is lost due to a network error (connect
went down, etc).

When the client explicitly closes the connection, your recieve callback will
be called and your will recieve zero bytes - when this happens you know that
the client is question has disconnected. To check for network errors you
will
have to catch the SocketException which you will be getting :)

HTH,

//Andreas

"Adam Clauss" <ca*****@tamu.edu> skrev i meddelandet
news:ex**************@TK2MSFTNGP11.phx.gbl...
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 no way to do raise an event for this? That way you know as soon

as the client disconnects?

There are events for Accepting, Connecting, Receiving, Sending... why not

one for disconnecting?

--
Adam Clauss
ca*****@tamu.edu


Nov 16 '05 #3

P: n/a
Adam,

It's all documented in the docs and its just a wrapper for the
underlaying WinSock
library. I felt the same at first but when you think about it, it makes
sence - how would
the socket notify the remote socket it disconnected? By sending information
and leting
the remote socket know. The most efficient notification message it can send
it an empty
one.

Agreed that a nice wrapped event where the Socket class checked the recive
on
triggered the event if it was zero byte would be nice - but the async call
runs on a
seperate thread and when you call Begin..() you pass the adress of the
return function
so it jumps directly to the callback and not back to the socket it self
which then forward
the result.

HTH,

//Andreas

"Adam Clauss" <ca*****@tamu.edu> skrev i meddelandet
news:us**************@TK2MSFTNGP12.phx.gbl...
Hmm... OnReceive gets called for OnDisconnect. Well, I suppose it works, just does not seem very logical.
Thanks!

--
Adam Clauss
ca*****@tamu.edu
"Andreas Håkansson" <andy.h (at) telia.com> wrote in message

news:uw**************@TK2MSFTNGP09.phx.gbl...
Adam,

There are two types of disconnects; when the client explicitly closes the
connection or when the connection is lost due to a network error (connect went down, etc).

When the client explicitly closes the connection, your recieve callback will be called and your will recieve zero bytes - when this happens you know that the client is question has disconnected. To check for network errors you
will
have to catch the SocketException which you will be getting :)

HTH,

//Andreas

"Adam Clauss" <ca*****@tamu.edu> skrev i meddelandet
news:ex**************@TK2MSFTNGP11.phx.gbl...
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 no way to do raise an event for this? That way you know as
soon as the client disconnects?

There are events for Accepting, Connecting, Receiving, Sending... why
not one for disconnecting?

--
Adam Clauss
ca*****@tamu.edu



Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.