pub struct WebSocketConfig {Show 13 fields
pub url: String,
pub headers: Vec<(String, String)>,
pub heartbeat: Option<u64>,
pub heartbeat_msg: Option<String>,
pub reconnect_timeout_ms: Option<u64>,
pub reconnect_delay_initial_ms: Option<u64>,
pub reconnect_delay_max_ms: Option<u64>,
pub reconnect_backoff_factor: Option<f64>,
pub reconnect_jitter_ms: Option<u64>,
pub reconnect_max_attempts: Option<u32>,
pub idle_timeout_ms: Option<u64>,
pub backend: TransportBackend,
pub proxy_url: Option<String>,
}Expand description
Configuration for WebSocket client connections.
This struct contains only static configuration settings. Runtime callbacks
(message handler, ping handler) are passed separately to connect().
§Connection Modes
§Handler Mode
- Use with
crate::websocket::WebSocketClient::connect. - Pass a message handler to
connect()to receive messages via callback. - Client spawns internal task to read messages and call handler.
- Supports automatic reconnection with exponential backoff.
- Reconnection config fields (
reconnect_*) are active. - Best for long-lived connections, Python bindings, callback-based APIs.
§Stream Mode
- Use with
crate::websocket::WebSocketClient::connect_stream. - Returns a
MessageReaderstream for the caller to read from. - Does NOT support automatic reconnection (reader owned by caller).
- Reconnection config fields are ignored.
- On disconnect, client transitions to CLOSED state and caller must manually reconnect.
Fields§
§url: StringThe URL to connect to.
headers: Vec<(String, String)>The default headers.
heartbeat: Option<u64>The optional heartbeat interval (seconds).
heartbeat_msg: Option<String>The optional heartbeat message.
reconnect_timeout_ms: Option<u64>The timeout (milliseconds) for reconnection attempts. Note: Only applies to handler mode. Ignored in stream mode. Must be non-zero when set.
reconnect_delay_initial_ms: Option<u64>The initial reconnection delay (milliseconds) for reconnects. Note: Only applies to handler mode. Ignored in stream mode.
reconnect_delay_max_ms: Option<u64>The maximum reconnect delay (milliseconds) for exponential backoff. Note: Only applies to handler mode. Ignored in stream mode.
reconnect_backoff_factor: Option<f64>The exponential backoff factor for reconnection delays. Note: Only applies to handler mode. Ignored in stream mode.
reconnect_jitter_ms: Option<u64>The maximum jitter (milliseconds) added to reconnection delays. Note: Only applies to handler mode. Ignored in stream mode.
reconnect_max_attempts: Option<u32>The maximum number of reconnection attempts before giving up. Note: Only applies to handler mode. Ignored in stream mode.
None: Unlimited reconnection attempts (default, recommended for production).Some(n): After n failed attempts, transition to CLOSED state.
idle_timeout_ms: Option<u64>The idle timeout (milliseconds) for the read task. When set, the read task will break and trigger reconnection if no data is received within this duration. Useful for detecting silently dead connections where the server stops sending without closing. Note: Only applies to handler mode. Ignored in stream mode.
backend: TransportBackendThe transport backend to use for the WebSocket connection.
Defaults to TransportBackend::Sockudo when the transport-sockudo
Cargo feature is enabled (the default), otherwise TransportBackend::Tungstenite.
When the feature is disabled, connect_with_server returns an error if
Sockudo is selected. Both backends pass headers into the HTTP
upgrade request. The Sockudo backend does not yet support proxy tunnels;
when Self::proxy_url is set, connect_with_server logs a warning
and routes through Tungstenite regardless of this field.
proxy_url: Option<String>Optional forward proxy URL for the WebSocket connection.
Routes the connection through an HTTP CONNECT tunnel. Accepts
http:// and https:// schemes; SOCKS schemes are not yet supported.
Implementations§
Source§impl WebSocketConfig
impl WebSocketConfig
Sourcepub fn builder() -> WebSocketConfigBuilder
pub fn builder() -> WebSocketConfigBuilder
Create an instance of WebSocketConfig using the builder syntax
Source§impl WebSocketConfig
impl WebSocketConfig
Sourcepub fn validate(&self) -> NetworkConfigResult<()>
pub fn validate(&self) -> NetworkConfigResult<()>
Checks whether all WebSocket settings are valid.
§Errors
Returns a NetworkConfigError if url is empty, the heartbeat interval or a
reconnection timing field is not positive, reconnect_backoff_factor is not finite and
at least 1.0, or reconnect_delay_initial_ms exceeds reconnect_delay_max_ms.
Trait Implementations§
Source§impl Clone for WebSocketConfig
impl Clone for WebSocketConfig
Source§fn clone(&self) -> WebSocketConfig
fn clone(&self) -> WebSocketConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more