473,842 Members | 1,922 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to detect network cable disconnection

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.
Nov 16 '05 #1
5 16956
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

"Vijay" <vi**********@y ahoo.com> wrote in message
news:a6******** *************** ***@posting.goo gle.com...
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.


Nov 16 '05 #2
"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.c om> wrote in message news:<#L******* ******@TK2MSFTN GP11.phx.gbl>.. .
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" <vi**********@y ahoo.com> wrote in message
news:a6******** *************** ***@posting.goo gle.com...
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.

Nov 16 '05 #3
On 29 Jul 2004 22:02:10 -0700, Vijay <vi**********@y ahoo.com> wrote:
"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.c om>
wrote in message news:<#L******* ******@TK2MSFTN GP11.phx.gbl>.. .
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.


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)size of(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.
--
klaus triendl
Nov 16 '05 #4

"Vijay" <vi**********@y ahoo.com> wrote in message
news:a6******** *************** ***@posting.goo gle.com...
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 RestoreMediaSen se and DisableMediaSen se.
--
Regards,

Jim Allison
jw*********@dig italcollimation .com
(de-mung by removing '.1')


Nov 16 '05 #5
That because client do recv() it receive immediately error and server can
receive it only after some operation
Arkady

"Vijay" <vi**********@y ahoo.com> wrote in message
news:a6******** *************** ***@posting.goo gle.com...
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.

Nov 16 '05 #6

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

Similar topics

8
2235
by: Steven Van Dyke | last post by:
Hi I need a code snippet to determine if my computer is connected to a network or not. There's probably a System.Net function for it, but I cannot find it. Thanks, Steve
1
3417
by: Sparky | last post by:
Hi I was wondering if someone can please enlighten me as to the best and most approved way to connect and disconnect network drives in vb.net. I have been using Mpr.dll API calls such as WNetCancelConnection2 and WNetAddConnection2, but these seem to be very flakey with drive disconnection (The drive conenction seems to be pretty good). I would have through that Microsocft would have provided a simple class you
13
2440
by: Shailesh Humbad | last post by:
Here is an advanced PHP question. Can anyone think of a way to detect the number of bytes written to output when a script is aborted? I am sending a large file to the client, and I want to record how many bytes are actually sent. I can detect abort of the script using a shutdown handler. In the shutdown handler, I tried ob_get_length, but it returns false. I tried to read the server's log file, but it is does not contain the...
0
1435
by: serban.lascu | last post by:
Hello! I have an application using LogonUser for authentification, running under XP SP2. LogonUser answers after a very long time (30 to 90 seconds) in the cases above: - I log on to Windows with the network connected, then unplug my network cable and launch the application. - I log on to Windows with the network connected, then disconnect my machine from the domain controller and launch the application.
15
7097
by: =?Utf-8?B?TVNU?= | last post by:
To demonstrate my problem, I have a very simple VB Windows application. It has a text box that is used to display a counter, a button to reset the counter, and a timer that increments the counter every second. I remote desktop to the computer hosting this application and run the application. It starts up and displays the counter incrementing every second. If I disconnect the network cable between the two computers for 10 seconds and...
5
1816
RevBooter
by: RevBooter | last post by:
hello all... got a bit of an issue going. i recently purchased a new laptop running vista, everything running swell. i also purchased a new router, as the router given to me by bt was not smart enough to connect through to work (did not support vpn tunnel passthrough etc), so i set up the router with a class A address (we need this to connect through to work), configured the router, and it was happy enough. the vista laptop connects fine through...
6
16621
by: afaichun | last post by:
Hi, I have the following situation. When I unplugged the network cable from a running ethernet card in a Linux box, there has no sign telling me the cable is unplugged from the system perspective (unless I try to perform socket connect). Does any one know how to accomplish this in C++? The reason behind this is I need to know if the connection is available for that particular network card in the application. Any help is appreciated.
14
9957
by: litusahoo | last post by:
Hi All, I have a lenovo 3000G/410 notebook ,yesterday and day before yesterday i was surfing the net using it and it was running for more than 36 works continously.After that when i unplugged the network cable and again connected after some time then it does not gets connected.The network cable unplugged error is being shown but the cable is fine as my friends are able to connect to internet using that same cable, but i am not.The light at the...
0
2100
by: Ontrace | last post by:
hello, I have Problem with Client Server Application when I unplug the client network cable, the server still read the network stream what function should I use to make server detect that the client is disconnect here the code... serverSide
0
10609
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10669
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10303
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9448
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7025
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5695
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4498
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3140
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.