473,320 Members | 1,957 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,320 software developers and data experts.

Socket Disconnected Notification

Hi,

I know there exist asynchronous socket methods for connecting,
receiving/sending data and disconnecting - but how do you know when the
socket has been terminated - can you assign an event handler or a
delegate as to when the socket is disconnected - either gracefully from
remote or shut down by "brute force"?

In short, something like this:

MySocket.Close += new EventHandler(MySocket_OnClosed);
Anyone?

Regards,
Vladimir Lushnikov

Nov 17 '05 #1
2 2891
Unfortunately, no, there is no "direct" event for Closing.

When a socket is closed, you will get a receive notification. When you then
try to read from the socket, you will get 0 bytes received. THIS 0 bytes
received is the notification when a socket gets closed.

--
Adam Clauss

"Vladimir Lushnikov" <vl****************@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Hi,

I know there exist asynchronous socket methods for connecting,
receiving/sending data and disconnecting - but how do you know when the
socket has been terminated - can you assign an event handler or a
delegate as to when the socket is disconnected - either gracefully from
remote or shut down by "brute force"?

In short, something like this:

MySocket.Close += new EventHandler(MySocket_OnClosed);
Anyone?

Regards,
Vladimir Lushnikov

Nov 17 '05 #2
Yes.
There is no "direct" event for Closing
and if you worry about the socket is closed or not . You have to check it by
yourself.

Best Regards,
Vuong
Tran Xuan
"Adam Clauss" <ca*****@tamu.edu> wrote in message
news:11*************@corp.supernews.com...
Unfortunately, no, there is no "direct" event for Closing.

When a socket is closed, you will get a receive notification. When you then try to read from the socket, you will get 0 bytes received. THIS 0 bytes
received is the notification when a socket gets closed.

--
Adam Clauss

"Vladimir Lushnikov" <vl****************@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Hi,

I know there exist asynchronous socket methods for connecting,
receiving/sending data and disconnecting - but how do you know when the
socket has been terminated - can you assign an event handler or a
delegate as to when the socket is disconnected - either gracefully from
remote or shut down by "brute force"?

In short, something like this:

MySocket.Close += new EventHandler(MySocket_OnClosed);
Anyone?

Regards,
Vladimir Lushnikov


Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Hameed Khan | last post by:
hi all, i am getting some problems with my first socket script. can any one of you point me why this is happening. the server script suppose to accept one connection at a time and send countdown...
3
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: dream machine | last post by:
Hi all, I'm try to check if the one client socket is really connected at my SocketServer . I build Client Socket with BeginAccept() , and I want to receive data with BegenReceive() call ! The...
5
by: Morten | last post by:
How do I detect if a client socket is no longer connected to the listen tcp socket ? I have tried with (just an example): --------------------- Socket tcpSocket; ...
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...
1
by: John Sheppard | last post by:
Thanks to everyone that responded to my previous Socket Programming question. Now I have run into some behavior that I don't quite understand. Programming environment. VS.NET 2003, C#, Windows...
0
by: Arno | last post by:
Hi, I've written a class for client-socket connection, but I get a lot of times the error message "Unable to read data from the transport connection" when restart reading the stream with...
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...
0
by: craze3 | last post by:
I have programmed an XML Socket Server to communicate with Flash. It doesn't print out the messages it has received from the flash until the server has been shut down. Any ideas? The part with...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.