none
Service / Client : Detect Network Disconnect RRS feed

  • Question

  • I was wondering if there is a way for the Service and the Client to be able to detect that there is no longer a internet connection? For example, someone unplugs the internet cable.
    Wednesday, November 11, 2015 9:02 PM

Answers

  • I implemented a IsAlive function on the Service so Clients can check every x seconds. The only thing I have to do now is implement something at the Service level to check for clients no longer there so the Service can clean up information about that connected client.

    It seems to me that it doesn't account for the client machine that is off-line, and it cannot connect  to even contact the service to see if it is alive.

    I have a simple function on the Service

    public bool IsAlive()
    {
         return true;
    }
    Each client, on a timer, makes this call every n seconds. If there is no Service available (no internet, cable unplugged, power outage at the service, service not running, etc) this will get an exception and therefore the client knows that the connection is down (Service is down).


    • Edited by brown71576 Thursday, November 12, 2015 6:48 PM
    • Proposed as answer by Grady_DongModerator Tuesday, November 17, 2015 5:41 AM
    • Marked as answer by brown71576 Tuesday, November 17, 2015 3:57 PM
    Thursday, November 12, 2015 6:47 PM

All replies

  • Hi brown71576,

    According to this case, I am not sure I can understood your question fully. Did you used

    WCF as your server?

    So, you want to monitor the client whether it connected with server-side. If so, as far as

    I know, we can used the Heartbeat Implementation to determine whether client is connected

    with server-side.

    For more information, please refer to the following articles:

    1.Detecting Client Connection in WCF Long Running Service (Heartbeat Implementation)

    I hope that will be helpful to you.

    Best Regards,

    Grady

    Thursday, November 12, 2015 5:51 AM
    Moderator
  • Hi brown71576,

    According to this case, I am not sure I can understood your question fully. Did you used

    WCF as your server?

    So, you want to monitor the client whether it connected with server-side. If so, as far as

    I know, we can used the Heartbeat Implementation to determine whether client is connected

    with server-side.

    For more information, please refer to the following articles:

    1.Detecting Client Connection in WCF Long Running Service (Heartbeat Implementation)

    I hope that will be helpful to you.

    Best Regards,

    Grady

    the Service and client are WCF. What I want to detect is network disruption like someone unplugging a internet cable from the machine the service is running on or someone unplugging the internet cable from the client machine. Implementation of graceful shutdown is easy enough so that's not what I am asking.

    Thursday, November 12, 2015 2:00 PM
  • the Service and client are WCF. What I want to detect is network disruption like someone unplugging a internet cable from the machine the service is running on or someone unplugging the internet cable from the client machine. Implementation of graceful shutdown is easy enough so that's not what I am asking.

    The only way is to use Ipconfig at the command prompt, pipe the output to a text file ipconfig >> sometextfile.txt and parse the text looking for  the IPv4 or (future is IPv6) address line. If there is no IP there, then the machine is not connected to a network.

    If the IP starts with 169., then the machine can communicate with other machines on the LAN, but the machine cannot access the WAN/Internet.

    http://www.pctechbytes.com/networking/169-254-address/

    You can do it programmically.

    Thursday, November 12, 2015 2:38 PM
  • I implemented a IsAlive function on the Service so Clients can check every x seconds. The only thing I have to do now is implement something at the Service level to check for clients no longer there so the Service can clean up information about that connected client.
    • Edited by brown71576 Thursday, November 12, 2015 5:15 PM
    Thursday, November 12, 2015 5:13 PM
  • I implemented a IsAlive function on the Service so Clients can check every x seconds. The only thing I have to do now is implement something at the Service level to check for clients no longer there so the Service can clean up information about that connected client.
    It seems to me that it doesn't account for the client machine that is off-line, and it cannot connect  to even contact the service to see if it is alive.
    Thursday, November 12, 2015 6:14 PM
  • I implemented a IsAlive function on the Service so Clients can check every x seconds. The only thing I have to do now is implement something at the Service level to check for clients no longer there so the Service can clean up information about that connected client.

    It seems to me that it doesn't account for the client machine that is off-line, and it cannot connect  to even contact the service to see if it is alive.

    I have a simple function on the Service

    public bool IsAlive()
    {
         return true;
    }
    Each client, on a timer, makes this call every n seconds. If there is no Service available (no internet, cable unplugged, power outage at the service, service not running, etc) this will get an exception and therefore the client knows that the connection is down (Service is down).


    • Edited by brown71576 Thursday, November 12, 2015 6:48 PM
    • Proposed as answer by Grady_DongModerator Tuesday, November 17, 2015 5:41 AM
    • Marked as answer by brown71576 Tuesday, November 17, 2015 3:57 PM
    Thursday, November 12, 2015 6:47 PM
  • Hi brown71576,

    Yes, I thought your solution is a good idea.

    Best Regards,

    Grady

    Tuesday, November 17, 2015 5:41 AM
    Moderator