The Nickvision::Network::NetworkMonitor
class provides an easy to use API to monitor for changes in the system's network connectivity.
Take the following program that checks the network status on startup and watches for changes:
{
std::cout <<
"Network state changed: " << (int)e.
getState() << std::endl;
}
int main()
{
if(netmon.getConnectedState() == NetworkState::ConnectedGlobal)
{
std::cout << "Connected to internet on startup." << std::endl;
}
else
{
std::cout << "No connectivity on startup." << std::endl;
}
std::cout << "Listening for changes..." << std::endl;
while(true)
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
A monitor of the system's network connection.
Definition networkmonitor.h:45
Events::Event< NetworkStateChangedEventArgs > & stateChanged()
Gets the StateChanged event. This event is invoked whenever the state of the network connection chang...
An event argument for when the network state is changed.
Definition networkstatechangedeventargs.h:35
NetworkState getState() const
Gets the network state.