c++windowsnetwork-programmingwxwidgetsconnectivity

Capturing network status change event


I am trying to get events when the internet connection is reestablished after it is lost. It is for a data transfer software that I am developing. If I lose the network during data transfer, I would like to be notified when it is back and continue the transfer automatically.

I can of course create a separate thread and check the network once in a while with a timer, but maybe there is a better option out there.

I am developing for windows mainly, in C++ (not .net).

I can also use wxwidgets (I use it for GUI) but I doubt it offers any related functionality.


Solution

  • You might want to check out the System Event Notification Server (SENS) API.

    I have not actually used it, but it seems like it supplies the events your looking for.

    EDIT:

    WMI appears to have all the information you need about various network connectivity and state changes. It also has an asynchronous event model that can be used to get notifications. The trick is, I suppose, generating the proper WMI query to get the information you want. This blog looks like the right type of query, and this MSDN explains how to handle the events asynchronously.