1

I have an application with one server and one client. How the client will know if the server cable is unplugged or disconnect? Is there event for that? I don’t want to set a timer to check occasionally if the server gets messages… And i don't want to use poll...

Thanks, Elad

Jaimesh
  • 830
  • 4
  • 24
  • 39
Eladh
  • 39
  • 2
  • With TCP it's easy: Just try to send anything, and after some time you would get an error back if the data could not be sent. – Some programmer dude Jul 31 '17 at 08:37
  • 1
    No amount of *pre-checking* can answer the question you probably want to ask - "can the server perform task X?" - only asking the server to actually perform task X will yield a reliable result. Suppose you obtain the answer that the cable is plugged in. *before* your code takes any action based on that fact though, the cable becomes unplugged. *by the time* your proposed event is delivered to your code though, it's gone ahead and acted as if the cable is plugged in. – Damien_The_Unbeliever Jul 31 '17 at 08:48
  • You _don't want_ to detect the network cable being unplugged. More specifically: TCP is designed to accommodate transient problems in the network. As long as one is not actually trying to send data, an interruption in connectivity is harmless; if that interruption is resolved before the next time any communication is attempted, your code will never notice, _and that's a good thing_. If you insist on defying this good advice, you're stuck with _some_ type of polling, such as enabling keep-alive at the TCP level or implementing in your own protocol, because TCP is designed to _not_ tell you. – Peter Duniho Aug 01 '17 at 00:31

1 Answers1

0

Refer at that questions :

Yopu have to analyze the connection status in all the phases and understand in wich phase are the problem, anyway why the connection doesn't works.

There are also other link that refer to your question :

Last method, work with NetworkChange.NetworkAvailabilityChanged Event

Link : enter link description here

Emanuel Pirovano
  • 226
  • 1
  • 6
  • 20