KtorWebSocketConnector
Opens WebSockets for coap+ws and coaps+ws (RFC 8323 §4, §8.3, §8.4) with the ktor client, so the same code runs wherever a ktor engine does. The default client runs on CIO on the JVM and Linux, on Darwin (URLSession, which brings up the cellular radio and honours VPN On Demand) on Apple, and on the runtime's own WebSocket in JS and Wasm. It names that engine, so another ktor engine the application links does not replace it; pass an HttpClient for a different one. The opening handshake asks for the subprotocol coap at /.well-known/coap (§4.1) and fails unless the server selects it.
val client = CoapClient(listOf(KtorWebSocketConnector()), scope)
client.get("coap+ws://example.org/sensors/temperature?u=Cel")coaps+ws runs wss on the engine's TLS, which must authenticate the server (RFC 8323 §9.2): its chain valid under the trust store and naming the URI's host (RFC 9525 §6). schemes lists coaps+ws only where the engine does that, as listing it is the connector's word that it runs TLS, and a CoAP client sends coaps+ws requests only then:
iOS and macOS: yes. URLSession checks the chain against the system's trust store, and the host name.
jsandwasmJs: yes. The browser's or Node.js's ownwssdoes.JVM and Android: no. CIO's TLS, ktor-network-tls 3.6.1, accepts a certificate without DNS names for any host name, and CIO checks an IP literal by the name its reverse DNS lookup gives.
Linux: no. CIO has no TLS on Linux native.
An HttpClient the application passes serves both schemes: passing one is the application's word that its engine authenticates wss servers. A CIO client on the JVM or Android has the name check above, so trust only certificate authorities that issue nothing but DNS names for your servers, or pass a client on an engine whose TLS checks names, such as one on the JDK's own TLS.
The connection reports PeerIdentity.None: ktor exposes no TLS peer certificate in common code.
Constructors
A connector on a client of its own, on the platform's engine named above and with WebSocket pings off (RFC 8323 §4.4); close closes it. It serves coap+ws everywhere, and coaps+ws only where that engine authenticates wss servers (the table above).
A connector on client, which must have the WebSockets plugin installed, preferably without a ping interval (RFC 8323 §4.4: WebSocket pings SHOULD NOT be used). The application closes it.