NetworkMonitor

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.

Since

2.32

Inheritors

Types

Link copied to clipboard
object Companion
Link copied to clipboard
data class NetworkMonitorImpl(val gioNetworkMonitorPointer: <Error class: unknown class><<Error class: unknown class>>) : NetworkMonitor

The NetworkMonitorImpl type represents a native instance of the NetworkMonitor interface.

Properties

Link copied to clipboard

More detailed information about the host's network connectivity. See g_network_monitor_get_connectivity() and #GNetworkConnectivity for more details.

Link copied to clipboard
open override val gioInitablePointer: <Error class: unknown class><<Error class: unknown class>>
Link copied to clipboard
abstract val gioNetworkMonitorPointer: <Error class: unknown class><<Error class: unknown class>>
Link copied to clipboard
abstract val gioProxyPointer: <Error class: unknown class><<Error class: unknown class>>
Link copied to clipboard

Whether the network is considered available. That is, whether the system has a default route for at least one of IPv4 or IPv6.

Link copied to clipboard

Whether the network is considered metered.

Functions

Link copied to clipboard
open fun canReach(connectable: SocketConnectable, cancellable: Cancellable? = null): <Error class: unknown class><Boolean>

Attempts to determine whether or not the host pointed to by

Link copied to clipboard
open fun canReachAsync(connectable: SocketConnectable, cancellable: Cancellable? = null, callback: AsyncReadyCallback?)

Asynchronously attempts to determine whether or not the host pointed to by @connectable can be reached, without actually trying to connect to it.

Link copied to clipboard
open fun canReachFinish(result: AsyncResult): <Error class: unknown class><Boolean>

Finishes an async network connectivity test. See g_network_monitor_can_reach_async().

Link copied to clipboard
open fun connect(connection: IoStream, proxyAddress: ProxyAddress, cancellable: Cancellable? = null): <Error class: unknown class><IoStream>

Given @connection to communicate with a proxy (eg, a #GSocketConnection that is connected to the proxy server), this does the necessary handshake to connect to @proxy_address, and if required, wraps the #GIOStream to handle proxy payload.

Link copied to clipboard
open fun connectAsync(connection: IoStream, proxyAddress: ProxyAddress, cancellable: Cancellable? = null, callback: AsyncReadyCallback?)

Asynchronous version of g_proxy_connect().

Link copied to clipboard
open fun connectFinish(result: AsyncResult): <Error class: unknown class><IoStream>

See g_proxy_connect().

Link copied to clipboard

Gets a more detailed networking state than g_network_monitor_get_network_available().

Link copied to clipboard

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.

Link copied to clipboard

Checks if the network is metered. See #GNetworkMonitor:network-metered for more details.

Link copied to clipboard
open fun init(cancellable: Cancellable? = null): <Error class: unknown class><Boolean>

Initializes the object implementing the interface.

Link copied to clipboard
open fun onNetworkChanged(connectFlags: <Error class: unknown class> = ConnectFlags(0u), handler: (networkAvailable: Boolean) -> Unit): <Error class: unknown class>

Emitted when the network configuration changes.

Link copied to clipboard

Some proxy protocols expect to be passed a hostname, which they will resolve to an IP address themselves. Others, like SOCKS4, do not allow this. This function will return false if @proxy is implementing such a protocol. When false is returned, the caller should resolve the destination hostname first, and then pass a #GProxyAddress containing the stringified IP address to g_proxy_connect() or g_proxy_connect_async().