473,396 Members | 2,061 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,396 software developers and data experts.

How do you know when a socket disconnects

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?

Jun 7 '06 #1
4 1701

"DaTurk" <mm******@hotmail.com> wrote in message
news:11**********************@f6g2000cwb.googlegro ups.com...
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.
Jun 7 '06 #2
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.

Ben Voigt wrote:
"DaTurk" <mm******@hotmail.com> wrote in message
news:11**********************@f6g2000cwb.googlegro ups.com...
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.


Jun 7 '06 #3
Will a asynch receive receive 0 bytes when the socket closes? Would it
be possible to use that as an indication?

Jun 7 '06 #4
DaTurk wrote:
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
Jun 7 '06 #5

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

Similar topics

0
by: Gavin Williams | last post by:
I am working on a multi-threaded server for a Windows 2000 system and since "fork" doesn't work that great in a Win32 environment, I am trying to use use the "threads" module instead. When a...
0
by: Heiko Pohl | last post by:
I got a problem with my server. I use a Socket in Blocking mode. I created an infine loop and wait for data using the Receive method. This works really good until the client disconnects....
4
by: Laszlo Csabi | last post by:
Hi Folks, I'm using c# to create a server client application. I have to check if the socket is in"CLOSE_WAIT" state. Anyone knows any solution for this? I tried to used Socket.Connected but...
3
by: Wojciech Halicki-Piszko | last post by:
How to know if connection is active after telnetlib.Telnet.open(host,port)?
5
by: DaTurk | last post by:
I have this application that has one sender, and multiple receivers, the receivers are subscribing to a multicast group to which the sender is sending information synchronously, while the receivers...
2
by: White Spirit | last post by:
I have a function within an application where a client connected to a server continuously sends data. The code on the server side is of the following form: Socket socket = receiveSocket;...
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...
10
by: cjard | last post by:
I have a client and server that enjoy the following simple dialogue: Client connects Client sends request Server sends response Client disconnects This is the way it must be. The response...
2
by: XenReborn | last post by:
Hi, I wrote a simple socket application, which connects to a simple socket server application I also wrote, the server opens a socket, listens, accepts connections, sends back a string of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.