ws-reconnect-client
Async WebSocket client for Rust with automatic reconnection and typed JSON message parsing.
Features
- Automatic reconnection with exponential backoff
- Generic typed JSON message parsing (
WebSocketClient<T>) - Automatic PING/PONG handling
- Stream-based API (
MessageStream<T>implementsfutures::Stream) - Builder pattern for configuration
- Built on
tokio-tungstenite
Installation
[]
= "0.1"
Quick Start
use ;
use Deserialize;
async
Configuration
use WsConnectionConfig;
let config = new
.with_retries // Max reconnection attempts (default: 20)
.with_backoff // Initial/max backoff in ms (default: 100ms, 10s)
.with_ping_interval // Ping interval in seconds (default: 5, 0 to disable)
.with_auto_reconnect; // Auto-reconnect on disconnect (default: true)
Low-Level API
For manual control over the connection:
use ;
use StreamExt;
let config = new;
let = connect_with_retry.await?;
// Send a subscription
send_subscription.await?;
// Read messages
while let Some = reader.next.await
License
MIT