pub struct WsClient {
pub url: String,
pub state: WsState,
pub auto_reconnect: bool,
pub max_reconnects: u32,
pub ping_interval: Duration,
pub pong_timeout: Duration,
pub max_queue_size: usize,
/* private fields */
}Expand description
WebSocket client driven by tick().
With the websocket feature the connection is real: a background thread
runs tungstenite (ws://, and
wss:// through rustls) and tick() exchanges messages with it without
blocking. Without the feature, connect reports an error event and the
client stays disconnected; before 0.3.0 it pretended to connect to any URL
and silently dropped every message.
Channel names given to send_on_channel and subscribe are local labels
for your own bookkeeping; they are not sent on the wire.
Fields§
§url: StringServer URL, ws:// or wss://.
state: WsStateCurrent connection state.
auto_reconnect: boolAuto-reconnect on unexpected disconnect.
max_reconnects: u32Max reconnect attempts before giving up (0 = unlimited).
ping_interval: DurationKeepalive ping interval.
pong_timeout: DurationClose connection if no pong received within this time.
max_queue_size: usizeMax size of outbound queue.
Implementations§
Source§impl WsClient
impl WsClient
Sourcepub fn new(url: impl Into<String>) -> Self
pub fn new(url: impl Into<String>) -> Self
A disconnected client for url. Call WsClient::connect to start.
Sourcepub fn disconnect(&mut self)
pub fn disconnect(&mut self)
Drop the connection; it reconnects on the next tick if
auto_reconnect is on.
Sourcepub fn send(&mut self, message: WsMessage) -> bool
pub fn send(&mut self, message: WsMessage) -> bool
Send a message. Queued if not currently connected.
Sourcepub fn send_on_channel(&mut self, channel: &str, message: WsMessage) -> bool
pub fn send_on_channel(&mut self, channel: &str, message: WsMessage) -> bool
Send a message labelled with a local channel name.
Sourcepub fn unsubscribe(&mut self, channel: &str)
pub fn unsubscribe(&mut self, channel: &str)
Remove a logical channel.
Sourcepub fn drain_events(&mut self) -> impl Iterator<Item = WsEvent> + '_
pub fn drain_events(&mut self) -> impl Iterator<Item = WsEvent> + '_
Take all events produced since the last call.
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Whether the connection is open.
Sourcepub fn messages_sent(&self) -> u64
pub fn messages_sent(&self) -> u64
Messages handed to the socket so far.
Sourcepub fn messages_received(&self) -> u64
pub fn messages_received(&self) -> u64
Messages received so far.
Sourcepub fn bytes_sent(&self) -> u64
pub fn bytes_sent(&self) -> u64
Payload bytes handed to the socket so far.
Sourcepub fn bytes_received(&self) -> u64
pub fn bytes_received(&self) -> u64
Payload bytes received so far.
Sourcepub fn pending_outbound(&self) -> usize
pub fn pending_outbound(&self) -> usize
Messages waiting to be sent.
Auto Trait Implementations§
impl !Sync for WsClient
impl Freeze for WsClient
impl RefUnwindSafe for WsClient
impl Send for WsClient
impl Unpin for WsClient
impl UnsafeUnpin for WsClient
impl UnwindSafe for WsClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more