@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.
type RawWebSocketMessage {
data Bytes
text Bool
}RawWebSocketMessage.data#
The payload bytes; for a text frame they are the UTF-8 encoding of the text.
data BytesRawWebSocketMessage.text#
True for a text frame, false for a binary frame.
text BoolWebSocket 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.
type WebSocket {
input ReadStream[WebSocketMessage]
output WriteStream[WebSocketMessage]
subprotocol String
}WebSocket.input#
Messages from the peer; null once the peer closes normally.
input ReadStream[WebSocketMessage]WebSocket.output#
Messages to the peer.
output WriteStream[WebSocketMessage]WebSocket.subprotocol#
The subprotocol the server selected during the handshake, or an empty string when none was negotiated.
subprotocol StringWebSocket.close#
Closes both streams, and with them the connection.
move fn close() Result[Void, Error]WebSocketKind Enum#
The kind of a WebSocket message.
enum WebSocketKind {
Text
Binary
Ping
}WebSocketKind.Binary#
A binary frame: the payload is arbitrary bytes.
BinaryWebSocketKind.Ping#
A ping control frame, at most 125 bytes. It is only written; the connection answers the peer’s pings with pongs itself.
PingWebSocketKind.Text#
A text frame: the payload is valid UTF-8.
TextWebSocketMessage Type#
One WebSocket message.
type WebSocketMessage {
data Bytes
kind WebSocketKind
}WebSocketMessage.data#
The payload bytes; for a text message they are the UTF-8 encoding of the text.
data BytesWebSocketMessage.kind#
Whether the message is text, binary, or a ping.
kind WebSocketKindWebSocketOptions Type#
Settings for opening a WebSocket client connection: headers, subprotocols, message size limit, time budget, TLS settings, and compression.
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.
compression Bool = falseWebSocketOptions.headers#
Extra handshake headers. Upgrade, Connection, Host and Sec-WebSocket-*
cannot be set.
headers HttpHeaders = headers()WebSocketOptions.max_message_bytes#
Largest message accepted or sent, in bytes. Must be positive; null sets no limit.
max_message_bytes Int? = nullWebSocketOptions.subprotocols#
Subprotocols to offer, in preference order.
subprotocols List[String] = []WebSocketOptions.timeout#
Time budget for connecting and completing the opening handshake. null waits indefinitely and a negative duration is rejected.
timeout Duration? = nullWebSocketOptions.tls#
TLS settings for wss URLs: trusted roots, client identity, and protocols.
tls TlsOptions = TlsOptions()WebSocketWire Type#
The part of WebSocketOptions the native handshake reads, in the native layout.
type WebSocketWire {
tls TlsOptions
compression Bool
max_message_bytes Int? = null
timeout Duration? = null
}WebSocketWire.compression#
The compression of the options.
compression BoolWebSocketWire.max_message_bytes#
The max_message_bytes of the options.
max_message_bytes Int? = nullWebSocketWire.timeout#
The timeout of the options.
timeout Duration? = nullWebSocketWire.tls#
The tls of the options.
tls TlsOptionsweb_socket_from Function#
Wraps a native WebSocket into a WebSocket.
fn web_socket_from(move native NativeWebSocket) WebSocket { ... }