Groups | Blog | Home
all groups > dotnet interop > july 2004 >

dotnet interop : How to detect network cable disconnection


vijaypatil78 NO[at]SPAM yahoo.com
7/29/2004 3:13:46 AM
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.

Dmitriy Lapshin [C# / .NET MVP]
7/29/2004 1:51:43 PM
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.

--
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

[quoted text, click to view]
vijaypatil78 NO[at]SPAM yahoo.com
7/29/2004 10:02:10 PM
[quoted text, click to view]
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.

[quoted text, click to view]
klaus triendl
7/30/2004 11:38:19 AM
[quoted text, click to view]

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.


--
jwallison
8/1/2004 6:31:58 PM

[quoted text, click to view]

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

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
jwallison.1@digitalcollimation.com
(de-mung by removing '.1')





Arkady Frenkel
8/2/2004 10:06:59 AM
That because client do recv() it receive immediately error and server can
receive it only after some operation
Arkady

[quoted text, click to view]

AddThis Social Bookmark Button