sigildocs

(sigil websocket connection)

(sigil websocket connection) - WebSocket Connection Management

Handles WebSocket connections with handshake, frame I/O, and state management. Supports both ws:// (plain) and wss:// (TLS) connections.

Exports

ws-connectionprocedure

Construct a ws-connection struct.

Test if a value is a ws-connection struct.

Get the socket field of a ws-connection struct.

Get the state field of a ws-connection struct.

Get the url field of a ws-connection struct.

Get the host field of a ws-connection struct.

Get the buffer field of a ws-connection struct.

Get the fragments field of a ws-connection struct.

Set the state field of a ws-connection struct.

Set the buffer field of a ws-connection struct.

Set the fragments field of a ws-connection struct.

Set the fragments field of a ws-connection struct.

ws-messageprocedure

Construct a ws-message struct.

ws-message?procedure

Test if a value is a ws-message struct.

Get the type field of a ws-message struct.

Get the data field of a ws-message struct.

parse-ws-urlprocedure

Parse WebSocket URL into components Returns (scheme host port path) or #f on error

Generate random 16-byte key and base64 encode

Calculate expected Sec-WebSocket-Accept value

Build HTTP upgrade request

Parse HTTP response status line Returns status code or #f

get-headerprocedure

Extract header value (case-insensitive)

Read HTTP response and validate handshake Returns #t on success, #f on failure

conn-writeprocedure

Write to socket (handles both TCP and TLS)

conn-readprocedure

Read from socket (handles both TCP and TLS)

conn-closeprocedure

Close socket (handles both TCP and TLS)

Set socket to non-blocking mode (handles both TCP and TLS)

ws-connectprocedure

Connect to a WebSocket server url: WebSocket URL (ws:// or wss://) Returns ws-connection on success, #f on failure

ws-connected?procedure

Check if connection is open

ws-sendprocedure

Send a text message

Send a binary message

ws-pingprocedure

Send a ping frame

ws-receiveprocedure

Receive a message (with async I/O support) Returns ws-message, 'closed, or #f on error When running in async scheduler, yields while waiting for data.

Internal: Read data and try to decode a message Returns ws-message, 'closed, 'need-more, or #f on error

Try to decode a complete message from buffer Returns ws-message, 'closed, 'need-more, or #f on error

process-frameprocedure

Process a decoded frame Returns ws-message, 'closed, 'need-more, or #f on error

ws-closeprocedure

Close the WebSocket connection