Struct generic_api_client::websocket::WebSocketConnection
source · pub struct WebSocketConnection<H: WebSocketHandler> { /* private fields */ }
Expand description
A struct
that holds a websocket connection.
Dropping this struct
terminates the connection.
Reconnecting
WebSocketConnection
automatically reconnects when an TungsteniteError occurs.
Note, that during reconnection, it is possible that the WebSocketHandler receives multiple identical messages
even though the message was sent only once by the server, or receives only one message even though
multiple identical messages were sent by the server, because there could be a time difference in the new connection and
the old connection.
You can use the reconnect_state() method to check if the connection is under a reconnection, or manually request a reconnection.
Implementations§
source§impl<H: WebSocketHandler> WebSocketConnection<H>
impl<H: WebSocketHandler> WebSocketConnection<H>
sourcepub async fn new(url: &str, handler: H) -> Result<Self, TungsteniteError>
pub async fn new(url: &str, handler: H) -> Result<Self, TungsteniteError>
Starts a new WebSocketConnection
to the given url using the given handler.
sourcepub async fn send_message(
&self,
message: WebSocketMessage
) -> Result<(), TungsteniteError>
pub async fn send_message( &self, message: WebSocketMessage ) -> Result<(), TungsteniteError>
Sends a message to the connection.
sourcepub fn reconnect_state(&self) -> ReconnectState
pub fn reconnect_state(&self) -> ReconnectState
Returns a ReconnectState for this connection.
See ReconnectState for more information.