startKeepAlive

open fun startKeepAlive(intervalMillis: Long): Result<Unit>(source)

Starts an opt-in, idle-aware background keepalive for this connection: every ~intervalMillis of output silence toward peer the server sends one 0x80 keepalive datagram, until stopKeepAlive, terminate, or server stop().

Server -> client keepalives refresh endpoint-independent (full-cone / restricted-cone) NAT mappings and verify the send path; they do not reliably refresh port-restricted or symmetric NATs - the authoritative keepalive is still the client's own (see keepAlive). A convenience over keepAlive, which is unchanged and still owns no timer.

The default implementation returns Result.failure - only the production UDPConnection supports a scheduled keepalive.

Return

Result.success once armed, or the failure that prevented it

Parameters

intervalMillis

output-idle time before a keepalive is sent; must be > 0. Defaults to TransportWireFormat.DEFAULT_KEEPALIVE_INTERVAL_MILLIS (20 s).


Starts the scheduled keepalive at the recommended interval (TransportWireFormat.DEFAULT_KEEPALIVE_INTERVAL_MILLIS, 20 s).

Return

Result.success once armed, or the failure that prevented it

See also