InMemoryConnections
In-memory connections for tests of CoAP over reliable transports (RFC 8323): listen binds a listener at an address, and connector connects to it, with a byte stream for coap+tcp and coaps+tcp or a message stream for coap+ws and coaps+ws. Delivery is immediate, ordered and lossless, as the transports promise; what a test needs beyond that it injects: InMemoryConnection.inject hands raw bytes to a side as if its peer had sent them, InMemoryConnection.reset breaks a connection.
Byte streams deliver every write in pieces of at most chunkSize bytes, so stream reassembly is exercised. tap sees every write.
val connections = InMemoryConnections()
val server = CoapServer(listOf(connections.listen(5683)), backgroundScope) { ... }
val client = CoapClient(listOf(connections.connector), backgroundScope)
client.get("coap+tcp://127.0.0.1:5683/hello")TLS is not simulated; a listener only reports the identities it was given. The connector lists coaps+tcp and coaps+ws as a connector that runs TLS does, so a CoAP client sends such URIs to it (RFC 8323 §9): it stands in for TLS in tests and must never carry real traffic.
Functions
Every connection opened so far, client side then accepted side of each, in the order they were opened.
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.