Connection

Represents an active session to a remote peer. Use it to inspect peer metadata and send payloads.

Properties

peerId

The unique identifier of the connected peer.

val peerId: String

state

Current connection state (see PeerState).

val state: PeerState

latencyMs

Best-effort round trip time (RTT) estimate in milliseconds.

val latencyMs: Long

Methods

send(data, callback)

Sends a payload to the peer and reports SendResult.

send(data: ByteArray, callback: (SendResult) -> Unit): void

close()

Closes the connection gracefully.

close(): void

Example

connection.send(payload) { result ->
    if (!result.ok) {
        log("send failed", result.traceId)
    }
}