connect

abstract suspend fun connect(url: String, protocols: List<String> = emptyList(), headers: Map<String, String> = emptyMap()): WebSocketConnection(source)

Opens a web socket connection to the given url and suspends until the connection is OPEN.

Parameters

url

the URL to connect to

protocols

an optional list of one or more web socket subprotocols that is intended to be spoken over the created web socket connection. The list should be provided in order of preference. The first one that is supported by the server will be selected during the handshake, and can be found at WebSocketConnection.protocol.

headers

custom headers to send during the web socket handshake. Support for custom handshake headers is optional. Implementations that don't support them must throw an IllegalArgumentException if headers is not empty.

Throws

if the headers map is not empty but the client doesn't support custom headers

if an error occurs during the connection.