libnick 2024.9.2
A cross-platform base for native Nickvision applications.
Loading...
Searching...
No Matches
Monitoring Network Connectivity

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:

using namespace Nickvision::Network;
void onNetChanged(const NetworkStateChangedEventArgs& e)
{
std::cout << "Network state changed: " << (int)e.getState() << std::endl;
}
int main()
{
netmon.stateChanged() += onNetChanged;
//Have to check initial state
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.
Definition curleasy.h:33