abla/websocket/tls

Generated from source.

Import with import "abla/websocket/tls".

Source: abla/websocket/tls/entry.ab

TlsWebSocketConnection (class)

resource class TlsWebSocketConnection(
    val stream: TlsConnection,
    var buffered: string,
    // The key the first version masked every frame with; each frame now takes a fresh one (frameMask). Kept for the constructor's shape.
    val maskingKey: string,
    var closed: bool,
    var readTimeoutMilliseconds: int = 0,
    val writeTimeoutMilliseconds: int = 0,
    // Random bytes for the masking keys of the frames to come (RFC 6455 5.3: a fresh key per frame), drawn 256 at a time, and how many are used.
    var maskPool: string = "",
    var maskUsed: int = 0
)

Owns the TLS stream and frame buffer for a WebSocket client connection.

webSocketTlsClient (fun)

fun webSocketTlsClient(
    host: string,
    path: string,
    port: int = 443,
    timeoutMilliseconds: int = 5000
): TlsWebSocketConnection

Connects to a WebSocket server over verified TLS and returns a closed connection if the handshake fails.

webSocketTlsClientWithCa (fun)

fun webSocketTlsClientWithCa(
    host: string,
    path: string,
    caPath: string,
    port: int = 443,
    timeoutMilliseconds: int = 5000
): TlsWebSocketConnection

Connects using the supplied CA file and returns a closed connection if TLS or WebSocket setup fails.

TlsWebSocketConnection.sendText (extension fun)

fun TlsWebSocketConnection.sendText(payload: string): bool

Sends one masked text frame and returns false for invalid UTF-8, a closed connection or a failed write.

TlsWebSocketConnection.sendBinary (extension fun)

fun TlsWebSocketConnection.sendBinary(payload: string): bool

Sends one masked binary frame and returns false if the connection is closed or the write fails.

TlsWebSocketConnection.setReadTimeout (extension fun)

fun TlsWebSocketConnection.setReadTimeout(milliseconds: int): void

Limits how long a read waits, for every later readFrame that does not name its own limit: the whole wait for a frame, from the call to its last byte, so a peer that sends a byte at a time cannot hold the reader for ever. 0 (the default) waits as long as it takes, which suits a connection that may stay quiet.

TlsWebSocketConnection.readFrame (extension fun)

fun TlsWebSocketConnection.readFrame(
    maximumPayload: int = 1048576,
    timeoutMilliseconds: int = -1
): WebSocketReadResult

Reads the next WebSocket frame and reports a parse error, end of stream or (with a limit) a timeout when unsuccessful. timeoutMilliseconds bounds the whole wait for the frame (-1, the default, takes the connection's setReadTimeout limit; 0 waits as long as it takes); a frame that is not complete in time is timedOut, the connection stays open and the call can be repeated (the bytes read stay buffered).

TlsWebSocketConnection.close (extension fun)

fun TlsWebSocketConnection.close(): bool

Closes the TLS connection after trying to send a normal WebSocket close frame and reports whether sending succeeded.

Built from Abla v0.2.79 source ba5d6b7d. Examples and generated signatures follow that source revision.