Skip to main content

WebSocketClientInner

Struct WebSocketClientInner 

Source
pub struct WebSocketClientInner { /* private fields */ }
Expand description

Owns the transport tasks and reconnect state used by WebSocketClient.

§Connection ownership

The client uses one reader and supports concurrent senders. In handler mode, a reader task dispatches incoming messages while a writer task serializes sends received over a channel. The controller owns the connection lifecycle and replaces both transport halves during reconnects.

Stream mode returns the reader to the caller. The client cannot replace that reader, so stream mode disables automatic reconnection.

§Heartbeats

When configured, a dedicated task sends heartbeat messages at the requested interval. Configure the interval below the server’s heartbeat deadline. Handler mode can also opt into a heartbeat timeout that reconnects when no frame arrives within a venue-specific duration. The timeout starts with each connection and resets on every inbound frame, including Ping and Pong.

§Reconnection

The writer task owns queued sends across reconnects. A successful reconnect installs the replacement writer and starts a reader for the new connection epoch. Depending on the configured authentication gate, buffered sends drain immediately or wait for the new session to authenticate. Failed authentication discards messages that remain buffered.

Implementations§

Source§

impl WebSocketClientInner

Source

pub async fn new_with_writer( config: WebSocketConfig, writer: SplitSink<BoxedWsTransport, Message>, ) -> Result<Self, TransportError>

Creates an inner WebSocket client with an existing writer.

This is used for stream mode where the reader is owned by the caller.

§Errors

Returns an error if the exponential backoff configuration is invalid.

Source

pub async fn connect_url( config: WebSocketConfig, message_handler: Option<MessageHandler>, ping_handler: Option<PingHandler>, ) -> Result<Self, TransportError>

Creates an inner WebSocket client.

§Errors

Returns an error if:

  • The connection to the server fails.
  • The exponential backoff configuration is invalid.
Source

pub async fn connect_with_server( url: &str, headers: Vec<(String, String)>, backend: TransportBackend, proxy_url: Option<&str>, ) -> Result<(SplitSink<BoxedWsTransport, Message>, MessageReader), TransportError>

Connects to the server and returns the split halves of the active transport.

Dispatches on backend to the matching transport implementation. The TransportBackend::Tungstenite backend is always available; the TransportBackend::Sockudo backend requires the transport-sockudo Cargo feature (enabled by default) and uses a custom HTTP/1.1 handshake path for upgrade headers.

When proxy_url is Some, both backends establish an HTTP CONNECT tunnel through the proxy before performing the WebSocket handshake, and each keeps its own handshake path over the resulting stream.

§Errors

Returns a TransportError if the URL is invalid, headers fail to parse, the TCP / TLS layer cannot be established, the proxy refuses the tunnel, or the WebSocket handshake is rejected by the peer. When the Sockudo backend is selected without the transport-sockudo feature, returns TransportError::Other.

Source§

impl WebSocketClientInner

Source

pub async fn reconnect(&mut self) -> Result<(), TransportError>

Reconnect with server.

Make a new connection with server. Use the new read and write halves to update self writer and read and heartbeat tasks.

For stream-based clients (created via WebSocketClient::stream_builder), reconnection is disabled because the reader is owned by the caller and cannot be replaced. Stream users should handle disconnections by creating a new connection.

The reconnect timeout bounds only connection establishment. Once the new writer is handed to the writer task the swap runs to completion, so buffered messages can never drain into a connection that lost its reader to a timeout; the post-connect steps are individually bounded by the writer task’s graceful-shutdown timeout.

§Errors

Returns an error if:

  • The reconnection attempt times out.
  • The connection to the server fails.
Source

pub fn is_alive(&self) -> bool

Returns whether the client’s transport tasks are still running.

Returns true if both the read and write tasks are still running. There may be some delay between the connection closing and the client detecting it.

Trait Implementations§

Source§

impl Debug for WebSocketClientInner

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for WebSocketClientInner

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Ungil for T
where T: Send,

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more