(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-connectionprocedureConstruct a ws-connection struct.
ws-connection?procedureTest if a value is a ws-connection struct.
ws-connection-socketprocedureGet the socket field of a ws-connection struct.
ws-connection-stateprocedureGet the state field of a ws-connection struct.
ws-connection-urlprocedureGet the url field of a ws-connection struct.
ws-connection-hostprocedureGet the host field of a ws-connection struct.
ws-connection-bufferprocedureGet the buffer field of a ws-connection struct.
ws-connection-fragmentsprocedureGet the fragments field of a ws-connection struct.
set-ws-connection-state!procedureSet the state field of a ws-connection struct.
set-ws-connection-buffer!procedureSet the buffer field of a ws-connection struct.
set-ws-connection-fragments!procedureSet the fragments field of a ws-connection struct.
%ws-message--typevariableSet the fragments field of a ws-connection struct.
ws-messageprocedureConstruct a ws-message struct.
ws-message?procedureTest if a value is a ws-message struct.
ws-message-typeprocedureGet the type field of a ws-message struct.
ws-message-dataprocedureGet the data field of a ws-message struct.
parse-ws-urlprocedureParse WebSocket URL into components Returns (scheme host port path) or #f on error
generate-ws-keyprocedureGenerate random 16-byte key and base64 encode
calculate-accept-keyprocedureCalculate expected Sec-WebSocket-Accept value
build-handshake-requestprocedureBuild HTTP upgrade request
parse-status-lineprocedureParse HTTP response status line Returns status code or #f
get-headerprocedureExtract header value (case-insensitive)
validate-handshakeprocedureRead HTTP response and validate handshake Returns #t on success, #f on failure
conn-writeprocedureWrite to socket (handles both TCP and TLS)
conn-readprocedureRead from socket (handles both TCP and TLS)
conn-closeprocedureClose socket (handles both TCP and TLS)
conn-set-non-blocking!procedureSet socket to non-blocking mode (handles both TCP and TLS)
ws-connectprocedureConnect to a WebSocket server url: WebSocket URL (ws:// or wss://) Returns ws-connection on success, #f on failure
ws-connected?procedureCheck if connection is open
ws-sendprocedureSend a text message
ws-send-binaryprocedureSend a binary message
ws-pingprocedureSend a ping frame
ws-receiveprocedureReceive 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.
receive-messageprocedureInternal: Read data and try to decode a message Returns ws-message, 'closed, 'need-more, or #f on error
try-decode-messageprocedureTry to decode a complete message from buffer Returns ws-message, 'closed, 'need-more, or #f on error
process-frameprocedureProcess a decoded frame Returns ws-message, 'closed, 'need-more, or #f on error
ws-closeprocedureClose the WebSocket connection