2.24 <GNetworkMonitor>

Interface: <GNetworkMonitor>

<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.

Properties

Property: network-monitor:connectivity self

More detailed information about the host’s network connectivity. See network-monitor:get-connectivity and <GNetworkConnectivity> for more details.

Its value is a <GNetworkConnectivity>.

It is read only.

Property: network-monitor:network-available self

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

Real-world networks are of course much more complicated than this; the machine may be connected to a wifi hotspot that requires payment before allowing traffic through, or may be connected to a functioning router that has lost its own upstream connectivity. Some hosts might only be accessible when a VPN is active. Other hosts might only be accessible when the VPN is not active. Thus, it is best to use network-monitor:can-reach? or network-monitor:can-reach-async to test for reachability on a host-by-host basis. (On the other hand, when the property is #f, the application can reasonably expect that no remote hosts at all are reachable, and should indicate this to the user in its UI.)

See also network-monitor:network-changed.

Its value is a boolean.

It is read only.

Property: network-monitor:network-metered self

Whether the network is considered metered.

That is, whether the system has traffic flowing through the default connection that is subject to limitations set by service providers. For example, traffic might be billed by the amount of data transmitted, or there might be a quota on the amount of traffic per month. This is typical with tethered connections (3G and 4G) and in such situations, bandwidth intensive applications may wish to avoid network activity where possible if it will cost the user money or use up their limited quota. Anything more than a few hundreds of kilobytes of data usage per hour should be avoided without asking permission from the user.

If more information is required about specific devices then the system network management API should be used instead (for example, NetworkManager or ConnMan).

If this information is not available then no networks will be marked as metered.

See also network-monitor:network-available.

Its value is a boolean.

It is read only.

Procedures

Method: network-monitor:can-reach-async self connectable [cancellable] [callback]
Method: can-reach-async self connectable [cancellable] [callback]

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 network-monitor:can-reach?.

When the operation is finished, callback will be called. You can then call network-monitor:can-reach-finish? to get the result of the operation.

self

Passed: a <GNetworkMonitor>.

a <GNetworkMonitor>

connectable

Passed: a <GSocketConnectable>.

a <GSocketConnectable>

cancellable

Passed, or left out: a <GCancellable>, or #f.

a <GCancellable>, or #f

callback

Passed, or left out: a procedure, or #f.

a GAsyncReadyCallback to call when the request is satisfied

See GAsyncReadyCallback for how it is called.

user-data

Not passed: guile-gi supplies it.

the data to pass to callback function

Method: network-monitor:can-reach-finish? self result ⇒ %return
Method: can-reach-finish? self result ⇒ %return

Finishes an async network connectivity test. See network-monitor:can-reach-async.

self

Passed: a <GNetworkMonitor>.

a <GNetworkMonitor>

result

Passed: a <GAsyncResult>.

a <GAsyncResult>

%return

Returned: a boolean.

#t if network is reachable, #f if not.

Method: network-monitor:can-reach? self connectable [cancellable] ⇒ %return
Method: can-reach? self connectable [cancellable] ⇒ %return

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 #t even when network-monitor:network-available is #f, if, for example, self can determine that connectable refers to a host on a local network.

If self believes that an attempt to connect to connectable will succeed, it will return #t. Otherwise, it will return #f and set error to an appropriate error (such as 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 network-monitor:can-reach-async.

self

Passed: a <GNetworkMonitor>.

a <GNetworkMonitor>

connectable

Passed: a <GSocketConnectable>.

a <GSocketConnectable>

cancellable

Passed, or left out: a <GCancellable>, or #f.

a <GCancellable>, or #f

%return

Returned: a boolean.

#t if connectable is reachable, #f if not.

Method: network-monitor:get-connectivity self ⇒ %return
Method: get-connectivity self ⇒ %return

Gets a more detailed networking state than network-monitor:get-network-available?.

If network-monitor:network-available is #f, then the connectivity state will be local.

If network-monitor:network-available is #t, then the connectivity state will be full (if there is full Internet connectivity), limited (if the host has a default route, but appears to be unable to actually reach the full Internet), or 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 limited and 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.

self

Passed: a <GNetworkMonitor>.

the <GNetworkMonitor>

%return

Returned: a <GNetworkConnectivity>.

the network connectivity state

Procedure: network-monitor:get-default ⇒ %return

Gets the default <GNetworkMonitor> for the system.

%return

Returned: a <GNetworkMonitor>.

a <GNetworkMonitor>, which will be a dummy object if no network monitor is available

Method: network-monitor:get-network-available? self ⇒ %return
Method: get-network-available? self ⇒ %return

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 network-monitor:network-available for more details.

self

Passed: a <GNetworkMonitor>.

the <GNetworkMonitor>

%return

Returned: a boolean.

whether the network is available

Method: network-monitor:get-network-metered? self ⇒ %return
Method: get-network-metered? self ⇒ %return

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

self

Passed: a <GNetworkMonitor>.

the <GNetworkMonitor>

%return

Returned: a boolean.

whether the connection is metered

Signals

Signal: network-monitor:network-changed

Connect a handler with (connect object network-monitor:network-changed handler). It is called as (handler self network-available).

Emitted when the network configuration changes.

self

Passed: a <GNetworkMonitor>.

network-available

Passed: a boolean.

the current value of network-monitor:network-available

Virtual methods

Virtual method: network-monitor:do-can-reach implementor self connectable [cancellable] ⇒ %return

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 #t even when network-monitor:network-available is #f, if, for example, self can determine that connectable refers to a host on a local network.

If self believes that an attempt to connect to connectable will succeed, it will return #t. Otherwise, it will return #f and set error to an appropriate error (such as 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 network-monitor:can-reach-async.

To override it in a new class, give register-type #:vfuncs `((can-reach . ,procedure)). The procedure is called as (procedure self connectable cancellable) ⇒ %return.

implementor

Passed: the class whose implementation to call: a class that implements <GNetworkMonitor>, or its GType number.

self

Passed: a <GNetworkMonitor>.

a <GNetworkMonitor>

connectable

Passed: a <GSocketConnectable>.

a <GSocketConnectable>

cancellable

Passed, or left out: a <GCancellable>, or #f.

a <GCancellable>, or #f

%return

Returned: a boolean.

#t if connectable is reachable, #f if not.

Virtual method: network-monitor:do-can-reach-async implementor self connectable [cancellable] [callback]

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 network-monitor:can-reach?.

When the operation is finished, callback will be called. You can then call network-monitor:can-reach-finish? to get the result of the operation.

To override it in a new class, give register-type #:vfuncs `((can-reach-async . ,procedure)). The procedure is called as (procedure self connectable cancellable callback user-data).

implementor

Passed: the class whose implementation to call: a class that implements <GNetworkMonitor>, or its GType number.

self

Passed: a <GNetworkMonitor>.

a <GNetworkMonitor>

connectable

Passed: a <GSocketConnectable>.

a <GSocketConnectable>

cancellable

Passed, or left out: a <GCancellable>, or #f.

a <GCancellable>, or #f

callback

Passed, or left out: a procedure, or #f.

a GAsyncReadyCallback to call when the request is satisfied

See GAsyncReadyCallback for how it is called.

user-data

Not passed: guile-gi supplies it.

the data to pass to callback function

Virtual method: network-monitor:do-can-reach-finish implementor self result ⇒ %return

Finishes an async network connectivity test. See network-monitor:can-reach-async.

To override it in a new class, give register-type #:vfuncs `((can-reach-finish . ,procedure)). The procedure is called as (procedure self result) ⇒ %return.

implementor

Passed: the class whose implementation to call: a class that implements <GNetworkMonitor>, or its GType number.

self

Passed: a <GNetworkMonitor>.

a <GNetworkMonitor>

result

Passed: a <GAsyncResult>.

a <GAsyncResult>

%return

Returned: a boolean.

#t if network is reachable, #f if not.

Virtual method: network-monitor:do-network-changed implementor self network-available

the virtual function pointer for the GNetworkMonitor::network-changed signal.

To override it in a new class, give register-type #:vfuncs `((network-changed . ,procedure)). The procedure is called as (procedure self network-available).

implementor

Passed: the class whose implementation to call: a class that implements <GNetworkMonitor>, or its GType number.

self

Passed: a <GNetworkMonitor>.

network-available

Passed: a boolean.