reinhardt-websockets
WebSocket support for the Reinhardt framework.
Overview
WebSocket protocol support for real-time bidirectional communication. Includes connection management, message routing, room management, and WebSocket handler traits for building interactive applications.
Installation
Add reinhardt to your Cargo.toml:
[]
= { = "0.1.0-alpha.1", = ["websockets"] }
# Or use a preset:
# reinhardt = { version = "0.1.0-alpha.1", features = ["standard"] } # Recommended
# reinhardt = { version = "0.1.0-alpha.1", features = ["full"] } # All features
Then import WebSocket features:
use ;
use ;
Note: WebSocket features are included in the standard and full feature presets.
Features
Implemented ✓
Connection Management
WebSocketConnection: Manages individual WebSocket connections- Connection ID tracking
- Send text, binary, and JSON messages
- Connection state management (open/closed)
- Async message sending with error handling
WebSocketErrorandWebSocketResult: Comprehensive error handling- Connection errors
- Send/receive errors
- Protocol errors
Message Types
Messageenum: Multiple message types support- Text messages
- Binary messages
- Ping/Pong messages
- Close messages with status codes
- JSON serialization/deserialization helpers
WebSocketMessagestruct: Structured message format with timestamps- Message type classification
- JSON data payload
- Optional timestamp support
Room Management
RoomManager: Multi-client room management- Join/leave room operations
- Broadcast messages to specific rooms
- Broadcast messages to all rooms
- Room size tracking
- List all active rooms
- Thread-safe with async/await support
Handler Traits
WebSocketHandler: Trait for implementing custom WebSocket handlerson_message: Handle incoming messageson_connect: Handle new connectionson_disconnect: Handle disconnections