Class NetworkMonitor

All Implemented Interfaces:
PointerInterface

public class NetworkMonitor extends Interface
#GNetworkMonitor provides an easy-to-use cross-platform API
for monitoring network connectivity. On Linux, the available
implementations are based on the kernel's netlink interface and
on NetworkManager.

There is also an implementation for use inside Flatpak sandboxes.

https://docs.gtk.org/gio/iface.NetworkMonitor.html

  • Field Details

  • Constructor Details

  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • canReach

      public boolean canReach(@Nonnull SocketConnectable connectable, @Nullable Cancellable cancellable) throws AllocationError
      Attempts to determine whether or not the host pointed to by
      @connectable can be reached, without actually trying to connect to
      it.

      This may return %TRUE even when #GNetworkMonitor:network-available
      is %FALSE, if, for example, @monitor can determine that
      @connectable refers to a host on a local network.

      If @monitor believes that an attempt to connect to @connectable
      will succeed, it will return %TRUE. Otherwise, it will return
      %FALSE and set @error to an appropriate error (such as
      %G_IO_ERROR_HOST_UNREACHABLE).

      Note that although this does not attempt to connect to
      @connectable, it may still block for a brief period of time (eg,
      trying to do multicast DNS on the local network), so if you do not
      want to block, you should use g_network_monitor_can_reach_async().
      Parameters:
      connectable - a #GSocketConnectable
      cancellable - a #GCancellable, or %NULL
      Returns:
      %TRUE if @connectable is reachable, %FALSE if not.
      Throws:
      AllocationError
    • canReachAsync

      public void canReachAsync(@Nonnull SocketConnectable connectable, @Nullable Cancellable cancellable, NetworkMonitor.OnAsyncReadyCallback callback, @Nullable Pointer user_data)
      Asynchronously attempts to determine whether or not the host
      pointed to by @connectable can be reached, without actually
      trying to connect to it.

      For more details, see g_network_monitor_can_reach().

      When the operation is finished, @callback will be called.
      You can then call g_network_monitor_can_reach_finish()
      to get the result of the operation.
      Parameters:
      connectable - a #GSocketConnectable
      cancellable - a #GCancellable, or %NULL
      callback - a #GAsyncReadyCallback to call when the request is satisfied
      user_data - the data to pass to callback function
    • canReachFinish

      public boolean canReachFinish(@Nonnull AsyncResult result) throws AllocationError
      Finishes an async network connectivity test.
      See g_network_monitor_can_reach_async().
      Parameters:
      result - a #GAsyncResult
      Returns:
      %TRUE if network is reachable, %FALSE if not.
      Throws:
      AllocationError
    • getConnectivity

      public int getConnectivity()
      Gets a more detailed networking state than
      g_network_monitor_get_network_available().

      If #GNetworkMonitor:network-available is %FALSE, then the
      connectivity state will be %G_NETWORK_CONNECTIVITY_LOCAL.

      If #GNetworkMonitor:network-available is %TRUE, then the
      connectivity state will be %G_NETWORK_CONNECTIVITY_FULL (if there
      is full Internet connectivity), %G_NETWORK_CONNECTIVITY_LIMITED (if
      the host has a default route, but appears to be unable to actually
      reach the full Internet), or %G_NETWORK_CONNECTIVITY_PORTAL (if the
      host is trapped behind a "captive portal" that requires some sort
      of login or acknowledgement before allowing full Internet access).

      Note that in the case of %G_NETWORK_CONNECTIVITY_LIMITED and
      %G_NETWORK_CONNECTIVITY_PORTAL, it is possible that some sites are
      reachable but others are not. In this case, applications can
      attempt to connect to remote servers, but should gracefully fall
      back to their "offline" behavior if the connection attempt fails.
      Returns:
      the network connectivity state
    • getNetworkAvailable

      public boolean getNetworkAvailable()
      Checks if the network is available. "Available" here means that the
      system has a default route available for at least one of IPv4 or
      IPv6. It does not necessarily imply that the public Internet is
      reachable. See #GNetworkMonitor:network-available for more details.
      Returns:
      whether the network is available
    • getNetworkMetered

      public boolean getNetworkMetered()
      Checks if the network is metered.
      See #GNetworkMonitor:network-metered for more details.
      Returns:
      whether the connection is metered
    • onNetworkChanged

      public SignalHandler onNetworkChanged(NetworkMonitor.OnNetworkChanged signal)
      Connect to signal "network-changed".
      See NetworkMonitor.OnNetworkChanged.onNetworkChanged(boolean) for signal description.
      Field SIGNAL_ON_NETWORK_CHANGED contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • getDefault

      public static NetworkMonitor getDefault()
      Gets the default #GNetworkMonitor for the system.
      Returns:
      a #GNetworkMonitor, which will be a dummy object if no network monitor is available
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()