listen

suspend fun listen(port: Int, scheme: CoapScheme = CoapScheme.COAP_TCP, host: String = LOOPBACK, clientIdentity: PeerIdentity = PeerIdentity.None, serverIdentity: PeerIdentity = PeerIdentity.None): InMemoryConnectionListener(source)

A listener for scheme at host and port. Clients reach it at Endpoint.Tcp(host, port) or Endpoint.WebSocket.of(host, port), which is its InMemoryConnectionListener.localEndpoint, and at every endpoint equal to that, however its host is written (RFC 7252 §6.6: Server as server, [2001:DB8::1] as 2001:db8::1, a ws URI without a port at port 80); a WebSocket client reaches it at any path. It sees each client at a port of its own. Accepted connections report clientIdentity as the client's identity, the client's side reports serverIdentity.

Throws

if a listener has an equal address already, or scheme is not a reliable one.