Manuscript Documentation
v2026.12.0

@std/net/websocket.ms#

Import each required symbol with import Name from "@std/net/websocket.ms".

RawWebSocketMessage Type#

A message as the native layer reports it.

Manuscript
type RawWebSocketMessage {
    data Bytes
    text Bool
}

RawWebSocketMessage.data#

The payload bytes; for a text frame they are the UTF-8 encoding of the text.

Manuscript
data Bytes

RawWebSocketMessage.text#

True for a text frame, false for a binary frame.

Manuscript
text Bool

WebSocket Type#

A WebSocket connection: input reads whole messages and output writes them. Move the streams to different tasks to receive and send at once. The connection closes, after a normal-closure frame, when both streams are closed. Closing the WebSocket closes both.

Manuscript
type WebSocket {
    input ReadStream[WebSocketMessage]
    output WriteStream[WebSocketMessage]
    subprotocol String
}

WebSocket.input#

Messages from the peer; null once the peer closes normally.

Manuscript
input ReadStream[WebSocketMessage]

WebSocket.output#

Messages to the peer.

Manuscript
output WriteStream[WebSocketMessage]

WebSocket.subprotocol#

The subprotocol the server selected during the handshake, or an empty string when none was negotiated.

Manuscript
subprotocol String

WebSocket.close#

Closes both streams, and with them the connection.

Manuscript
move fn close() Result[Void, Error]

WebSocketKind Enum#

The kind of a WebSocket message.

Manuscript
enum WebSocketKind {
    Text
    Binary
    Ping
}

WebSocketKind.Binary#

A binary frame: the payload is arbitrary bytes.

Manuscript
Binary

WebSocketKind.Ping#

A ping control frame, at most 125 bytes. It is only written; the connection answers the peer’s pings with pongs itself.

Manuscript
Ping

WebSocketKind.Text#

A text frame: the payload is valid UTF-8.

Manuscript
Text

WebSocketMessage Type#

One WebSocket message.

Manuscript
type WebSocketMessage {
    data Bytes
    kind WebSocketKind
}

WebSocketMessage.data#

The payload bytes; for a text message they are the UTF-8 encoding of the text.

Manuscript
data Bytes

WebSocketMessage.kind#

Whether the message is text, binary, or a ping.

Manuscript
kind WebSocketKind

WebSocketOptions Type#

Settings for opening a WebSocket client connection: headers, subprotocols, message size limit, time budget, TLS settings, and compression.

Manuscript
type WebSocketOptions {
    headers HttpHeaders = headers()
    subprotocols List[String] = []
    max_message_bytes Int? = null
    timeout Duration? = null
    tls TlsOptions = TlsOptions()
    compression Bool = false
}

WebSocketOptions.compression#

When True, offers per-message compression during the handshake; it applies only if the peer agrees.

Manuscript
compression Bool = false

WebSocketOptions.headers#

Extra handshake headers. Upgrade, Connection, Host and Sec-WebSocket-* cannot be set.

Manuscript
headers HttpHeaders = headers()

WebSocketOptions.max_message_bytes#

Largest message accepted or sent, in bytes. Must be positive; null sets no limit.

Manuscript
max_message_bytes Int? = null

WebSocketOptions.subprotocols#

Subprotocols to offer, in preference order.

Manuscript
subprotocols List[String] = []

WebSocketOptions.timeout#

Time budget for connecting and completing the opening handshake. null waits indefinitely and a negative duration is rejected.

Manuscript
timeout Duration? = null

WebSocketOptions.tls#

TLS settings for wss URLs: trusted roots, client identity, and protocols.

Manuscript
tls TlsOptions = TlsOptions()

WebSocketWire Type#

The part of WebSocketOptions the native handshake reads, in the native layout.

Manuscript
type WebSocketWire {
    tls TlsOptions
    compression Bool
    max_message_bytes Int? = null
    timeout Duration? = null
}

WebSocketWire.compression#

The compression of the options.

Manuscript
compression Bool

WebSocketWire.max_message_bytes#

The max_message_bytes of the options.

Manuscript
max_message_bytes Int? = null

WebSocketWire.timeout#

The timeout of the options.

Manuscript
timeout Duration? = null

WebSocketWire.tls#

The tls of the options.

Manuscript
tls TlsOptions

web_socket_from Function#

Wraps a native WebSocket into a WebSocket.

Manuscript
fn web_socket_from(move native NativeWebSocket) WebSocket { ... }