deno_websocket extension provides WebSocket client and server functionality, enabling real-time bidirectional communication over TCP connections.
Location
ext/websocket/
What It Provides
WebSocket Client
Create WebSocket connections:Custom Headers
Send custom headers during handshake:Subprotocols
Negotiate WebSocket subprotocols:Binary Data
Handle binary messages:WebSocketStream
Streams-based WebSocket API:Server-Side WebSocket
Upgrade HTTP connections to WebSocket:Protocol Support
HTTP/1.1 WebSocket
Standard WebSocket upgrade:HTTP/2 WebSocket
WebSocket over HTTP/2:TLS/SSL
Secure WebSocket connections:Key Operations
Rust operations exposed to JavaScript:Implementation Details
Extension Definition
Handshake Process
HTTP/1.1 Handshake
HTTP/2 Handshake
Message Types
Resource Management
Frame Handling
Usesfastwebsockets crate:
- Text frames
- Binary frames
- Ping/Pong frames
- Close frames with status codes
- Fragmented messages (automatic assembly)
Backpressure
Monitors buffered amount:Performance Features
Vectored Writes
Optimized message sending:Auto-masking
Client-side frame masking:Automatic Ping/Pong
Keep-alive mechanism:Fragment Collection
Automatic message reassembly:Close Codes
Standard WebSocket close codes:Error Handling
File Structure
Standards Compliance
Implements:- RFC 6455 - WebSocket Protocol
- WebSocket API
- WebSocketStream
See Also
- Fetch Extension - HTTP client
- HTTP Extension - HTTP server
- Web Extension - Base types and streams