Usage
Once you set up the details in Essential Kit Settings, you need to import the namespace for starting the network status detection.
1
using VoxelBusters.CoreLibrary;
2
using VoxelBusters.EssentialKit;
Copied!
For detecting the network status you need to start the notifier. Once there is a change in network status, events are fired to capture the status. You need to register for the events first to get the network status.
1
private void OnEnable()
2
{
3
// register for events
4
NetworkServices.OnHostReachabilityChange += OnHostReachabilityChange;
5
NetworkServices.OnInternetConnectivityChange += OnInternetConnectivityChange;
6
}
7
8
private void OnDisable()
9
{
10
// unregister from events
11
NetworkServices.OnHostReachabilityChange -= OnHostReachabilityChange;
12
NetworkServices.OnInternetConnectivityChange -= OnInternetConnectivityChange;
13
}
Copied!
1
private void OnInternetConnectivityChange(NetworkServicesInternetConnectivityStatusChangeResult result)
2
{
3
Debug.Log("Received internet connectivity changed event.");
4
Debug.Log("Internet connectivity status: " + result.IsConnected);
5
}
6
7
private void OnHostReachabilityChange(NetworkServicesHostReachabilityStatusChangeResult result)
8
{
9
Debug.Log("Received host reachability changed event.");
10
Debug.Log("Host reachability status: " + result.IsReachable);
11
}
Copied!
As you can see, you can either listen to general internet connectivity or to a specific host. You need to set the host in the Host address section of settings properties.

Start detecting the status

Start the network notifier to enable detection of network connectivity and receive the events.
1
NetworkServices.StartNotifier();
Copied!

Stop detecting the status

Once you are done with your requirement on detecting network connectivity, you can stop the notifier by calling StopNotifier.
1
NetworkServices.StopNotifier();
Copied!

Checking status any time

Once after you called StartNotifier, there are options to check the status of the network by some utility methods.
1
bool isInternetActive = NetworkServices.IsInternetActive;
Copied!
1
bool isHostReachable = NetworkServices.IsHostReachable;
Copied!
1
bool isNotifierActive = NetworkServices.IsNotifierActive;
Copied!
It's always good to stop the network notifier if you aren't using the status. This helps to save some network data and device battery for users as the plugin don't need to pool the servers.
Last modified 1mo ago