Module http::websocket
WebSocket (RFC 6455), client + server.
Built on the same blocking-socket model as std/http/http.h (see that header's backend-selection note — a std/sched/io_nb_*.sc backend must be included before this file too) plus std::sha1 (RFC 6455's handshake is specified in terms of SHA-1, not a general recommendation — see std/crypto/sha1.h's own note) and std::base64_encode/base64_decode.
Scope: masking (client-to-server, per the RFC's mandatory requirement) and unmasking are fully handled. WsConn::recv returns single frames (fragments and pings included, as before); WsConn::recv_message reassembles fragmented messages and answers pings itself. A server can accept on its own listening socket (ws_listen + accept) or upgrade a request on an HttpServer/Router connection (accept_upgrade), so HTTP and WebSocket endpoints share one port. wss:// runs over TLS (std/tls: connect_url / connect_tls on the client; accept_upgrade on an HTTPS HttpServer). No extensions (permessage-deflate).
Structs
| WsMessage | |
| WsConn |
Functions
| ws_listen | Creates a blocking listening socket on 'port'. Returns the fd, or -1 on failure. |
| ws_is_upgrade | 1 if 'req' asks for a WebSocket upgrade (GET with Upgrade: websocket, Connection: upgrade and a Sec-WebSocket-Key). |
Macros
| WS_OPCODE_CONTINUATION | |
| WS_OPCODE_TEXT | |
| WS_OPCODE_BINARY | |
| WS_OPCODE_CLOSE | |
| WS_OPCODE_PING | |
| WS_OPCODE_PONG | |
| WS_DEFAULT_TIMEOUT_MS | Opening-handshake limit WsConn::connect uses (see connect_timeout). |