Expand description
§Armature WebSocket
WebSocket server and client support for the Armature framework using tokio-tungstenite.
§Features
- WebSocket server with connection management
- WebSocket client for outbound connections
- Room-based message broadcasting
- Connection state management
- Heartbeat/ping-pong support
- JSON message serialization
§Example
use armature_websocket::{WebSocketServer, WebSocketHandler, Message};
use async_trait::async_trait;
struct ChatHandler;
#[async_trait]
impl WebSocketHandler for ChatHandler {
async fn on_connect(&self, connection_id: &str) {
println!("Client connected: {}", connection_id);
}
async fn on_message(&self, connection_id: &str, message: Message) {
println!("Received from {}: {:?}", connection_id, message);
}
async fn on_disconnect(&self, connection_id: &str) {
println!("Client disconnected: {}", connection_id);
}
}Structs§
- Close
Frame - A struct representing the close command.
- Connection
- A WebSocket connection.
- Logging
Handler - A no-op handler that logs messages.
- Message
- A WebSocket message.
- Room
- A room for grouping WebSocket connections.
- Room
Manager - Manages rooms and their members.
- WebSocket
Client - WebSocket client for connecting to WebSocket servers.
- WebSocket
Client Builder - Builder for WebSocket client.
- WebSocket
Server - WebSocket server.
- WebSocket
Server Builder - Builder for WebSocket server configuration.
- WebSocket
Server Config - WebSocket server configuration.
Enums§
- Connection
State - Connection state.
- Message
Type - Message type enumeration.
- RawMessage
- An enum representing the various forms of a WebSocket message.
- WebSocket
Error - WebSocket error type.
Traits§
- WebSocket
Handler - Trait for handling WebSocket events.
Type Aliases§
- Connection
Id - Unique identifier for a connection.
- RoomId
- Unique identifier for a room.
- WebSocket
Result - Result type for WebSocket operations.