How do you know when a socket disconnects

  • Thread starter Thread starter DaTurk
  • Start date Start date
D

DaTurk

I want to know when a socket disconnects so I can attempt to reconnect.


Is there any special type of pattern to doing this? Is there an evnt
raised?
 
DaTurk said:
I want to know when a socket disconnects so I can attempt to reconnect.


Is there any special type of pattern to doing this? Is there an evnt
raised?
If the other endpoint sends RST, you will get an error the next time you
call any read or write function. If the network breaks (remote endpoint
rebooted, too many lost packets, whatever), then TCP typically retries for
an extremely long time (less and less frequently) without ever determining
the connection is lost. Many TCP-based protocols have keep-alive and
timeout for this reason.
 
Thanks for the reply, so if I wanted to know when a socket disconnected
so then I could reconnect for a certain amount of times, how would one
do this. I can't really find anything about it.
 
Will a asynch receive receive 0 bytes when the socket closes? Would it
be possible to use that as an indication?
 
DaTurk said:
Will a asynch receive receive 0 bytes when the socket closes? Would it
be possible to use that as an indication?

The Receive functions return 0 bytes to indicate that a connection has
been closed. Take a look at the MSDN help page for Socket.Receive. You
should also put a try/catch around the whole thing.

hth,
Max
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top