pub struct SocketClient {
pub writer_tx: UnboundedSender<WriterCommand>,
/* private fields */
}Fields§
§writer_tx: UnboundedSender<WriterCommand>Implementations§
Source§impl SocketClient
impl SocketClient
Sourcepub async fn connect(
config: SocketConfig,
post_connection: Option<Arc<dyn Fn() + Send + Sync>>,
post_reconnection: Option<Arc<dyn Fn() + Send + Sync>>,
post_disconnection: Option<Arc<dyn Fn() + Send + Sync>>,
) -> Result<Self>
pub async fn connect( config: SocketConfig, post_connection: Option<Arc<dyn Fn() + Send + Sync>>, post_reconnection: Option<Arc<dyn Fn() + Send + Sync>>, post_disconnection: Option<Arc<dyn Fn() + Send + Sync>>, ) -> Result<Self>
Sourcepub fn connection_mode(&self) -> ConnectionMode
pub fn connection_mode(&self) -> ConnectionMode
Returns the current connection mode.
Sourcepub fn is_active(&self) -> bool
pub fn is_active(&self) -> bool
Check if the client connection is active.
Returns true if the client is connected and has not been signalled to disconnect.
The client will automatically retry connection based on its configuration.
Sourcepub fn is_reconnecting(&self) -> bool
pub fn is_reconnecting(&self) -> bool
Check if the client is reconnecting.
Returns true if the client lost connection and is attempting to reestablish it.
The client will automatically retry connection based on its configuration.
Sourcepub fn is_disconnecting(&self) -> bool
pub fn is_disconnecting(&self) -> bool
Check if the client is disconnecting.
Returns true if the client is in disconnect mode.
Sourcepub fn is_closed(&self) -> bool
pub fn is_closed(&self) -> bool
Check if the client is closed.
Returns true if the client has been explicitly disconnected or reached
maximum reconnection attempts. In this state, the client cannot be reused
and a new client must be created for further connections.
Sourcepub async fn close(&self)
pub async fn close(&self)
Close the client.
Controller task will periodically check the disconnect mode and shutdown the client if it is not alive.
Sourcepub async fn send_bytes(&self, data: Vec<u8>) -> Result<(), SendError>
pub async fn send_bytes(&self, data: Vec<u8>) -> Result<(), SendError>
Sends a message of the given data.
Returns Ok(()) when the message is enqueued to the writer channel. This does NOT
guarantee delivery: if a disconnect occurs concurrently, the writer task may drop the
message. During reconnection, messages are buffered and replayed on the new connection.
§Errors
Returns an error if sending fails.