Skip to main content

Module websocket

Module websocket 

Source
Expand description

Pure-Rust W3C WebSocket Client with RFC 6455 Frame Serialization, Handshake & TLS (wss://).

Provides:

  • Complete RFC 6455 frame encoding and decoding with masking and control frame processing.
  • Cryptographic Sec-WebSocket-Key generation and SHA-1 Sec-WebSocket-Accept validation.
  • Native TLS transport for wss:// connections via Mozilla WebPKI root certificates and rustls.
  • Asynchronous background worker stream reading, heartbeat Ping/Pong processing, and queueing.

Structs§

WebSocket
W3C WebSocket client interface supporting ws:// and TLS wss://.
WsFragment
Ongoing fragmented message tracking state.
WsFrame
A decoded RFC 6455 WebSocket frame.

Enums§

WsError
Errors occurring during WebSocket communication.
WsMessage
High-level WebSocket message.
WsOpcode
RFC 6455 WebSocket Opcode.
WsState
State of the WebSocket connection per W3C specification.

Constants§

DEFAULT_MAX_FRAME_SIZE
Maximum default frame payload size before automatically fragmenting (64 KB).

Functions§

base64_encode
Standard base64 encoding.
compute_sec_websocket_accept
Computes the expected RFC 6455 Sec-WebSocket-Accept header value from client key.
decode_frame
Decodes an RFC 6455 frame from a byte buffer.
encode_frame
Encodes an RFC 6455 frame into bytes.
generate_mask_key
Generates an unpredictable 32-bit masking key for client frames (RFC 6455 §5.3).
generate_sec_websocket_key
Generates a cryptographically random 16-byte base64 nonce for Sec-WebSocket-Key (RFC 6455 §4.1).
sha1
Computes FIPS 180-1 SHA-1 digest in pure Rust.