How to detect network cable disconnection

V

Vijay

Hi all,
i have TCP client server application written in C# using async
socket methods, eg BeginReceive(), BeginEnd() etc

server is continuesly running in the background, client connect to
server and recives data from server.
If server application shuts down client immedeatly recieves
disconnection or exception, but im not able to detect if some body
removed network cable of node , where server is running.
Client continuesly waits for data from server

Also netstat command shows the client in ESTABLISED state.

How to handle this situation.
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi Vijay,

There's a subsystem in Windows called System Notification Services. You can
get events such as "Network cable disconnected" from there. Please consult
MSDN on System Notification Services API.
 
V

Vijay

Dmitriy Lapshin said:
Hi Vijay,

There's a subsystem in Windows called System Notification Services. You can
get events such as "Network cable disconnected" from there. Please consult
MSDN on System Notification Services API.
The problem is client and server are running on two different nodes,
say A and B respectively.
they are connected and TCP connection and sockets are in ESTABLISHED
state

suppose i disconnect the node b where server is running , How can can
i get notification in CLient, because client node is still connected
to network.

when i see state of client using netstate it shows ESTABLISED state.
--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

Vijay said:
Hi all,
i have TCP client server application written in C# using async
socket methods, eg BeginReceive(), BeginEnd() etc

server is continuesly running in the background, client connect to
server and recives data from server.
If server application shuts down client immedeatly recieves
disconnection or exception, but im not able to detect if some body
removed network cable of node , where server is running.
Client continuesly waits for data from server

Also netstat command shows the client in ESTABLISED state.

How to handle this situation.
 
K

klaus triendl

The problem is client and server are running on two different nodes,
say A and B respectively.
they are connected and TCP connection and sockets are in ESTABLISHED
state

suppose i disconnect the node b where server is running , How can can
i get notification in CLient, because client node is still connected
to network.

when i see state of client using netstate it shows ESTABLISED state.

you can't get a notification immediately because once a tcp/ip connection
is established it is valid until it is closed explicitly;
there is one way to determine whether both hosts are still alive: set the
keep-alive option on the socket:

bool enable;
int opt = (enable ? ~0: 0);
setsockopt(so, SOL_SOCKET, SO_KEEPALIVE, (char*)&opt,
(socklen_t)sizeof(opt));

every 2hours (i think this is the default) there is sent out a keep-alive
packet to determine whether the remote host is still there.
 
J

jwallison

Vijay said:
Hi all,
i have TCP client server application written in C# using async
socket methods, eg BeginReceive(), BeginEnd() etc

server is continuesly running in the background, client connect to
server and recives data from server.
If server application shuts down client immedeatly recieves
disconnection or exception, but im not able to detect if some body
removed network cable of node , where server is running.
Client continuesly waits for data from server

Also netstat command shows the client in ESTABLISED state.

How to handle this situation.

================================================

The following may or may not suit your needs -

From "Media Sense" (W2K+) topic on MSDN:
"Media sense support allows the protocol stack to react to events and remove
stale parameters. For example, if a Windows 2000 computer is unplugged from
the network (assuming the network adapter supports Media Sense), after a
damping period of 20 seconds, TCP/IP invalidates the parameters associated
with the network that has been disconnected. The IP address(es) no longer
allow sends, and any routes associated with the interface are invalidated.

If an application is bound to a socket that is using an address that is
invalidated, it should handle the event and recover in a graceful way, such
as attempting to use another IP address on the system or notifying the user
of the disconnect."

See also MSDN topics RestoreMediaSense and DisableMediaSense.


--
Regards,

Jim Allison
(e-mail address removed)
(de-mung by removing '.1')
 
A

Arkady Frenkel

That because client do recv() it receive immediately error and server can
receive it only after some operation
Arkady
 

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

Top