install

suspend fun install(peer: Endpoint, security: ClientMessageSecurity)(source)

Protects every request to peer with security from now on, replacing what was installed for it.


suspend fun install(client: CoapClient, server: CoapUri, security: ClientMessageSecurity): Endpoint(source)

Protects every request that client sends to the server of server with security from now on: the endpoint of server's scheme, host and port, which the client's own resolver (dev.kcoap.coap.client.CoapClientConfig.resolver) finds, as for the client's requests. A resolver that maps one name to different addresses over time needs install again for each.

The resolver's failures reach the caller as they reach the client's requests (dev.kcoap.coap.client.EndpointResolver): a lookup that fails at runtime, whatever the resolver threw for it, a platform's DNS exception or the cancellation of its own withTimeout included, is a CoapException with UNRESOLVED_HOST and that failure as cause, which Swift catches as an NSError. Nothing is installed then.

Return

the endpoint the protection was installed for.

Throws

with UNRESOLVED_HOST when the resolver's lookup fails at runtime.

when the resolver cannot resolve the host of server by design, such as a host name given to EndpointResolver.Default.