pub struct SocketClient {
pub writer_tx: UnboundedSender<WriterCommand>,
/* private fields */
}Expand description
A suffix-framed TCP client with optional TLS and automatic reconnection.
The internal writer task serializes concurrent calls to Self::send_bytes. The configured
suffix frames all sent and received messages, and an optional heartbeat task sends its payload
at the configured interval. See SocketConfig for framing and reconnect policy.
Fields§
§writer_tx: UnboundedSender<WriterCommand>Implementations§
Source§impl SocketClient
impl SocketClient
Sourcepub fn reconnect_handle(&self) -> SocketReconnectHandle
pub fn reconnect_handle(&self) -> SocketReconnectHandle
Returns a cloneable handle to this client’s reconnect controller.
Sourcepub fn request_reconnect(&self) -> bool
pub fn request_reconnect(&self) -> bool
Requests that the controller replace the active transport.
Returns true only when this call transitions the client from active to reconnecting.
Duplicate, disconnecting, and closed requests return false.
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
Returns whether 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
Returns whether 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
Returns whether 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
Returns whether 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 fn begin_shutdown(&self)
pub fn begin_shutdown(&self)
Requests shutdown without waiting for the controller task.
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.
Sourcepub fn builder() -> SocketClientBuilder
pub fn builder() -> SocketClientBuilder
Returns a builder for a new SocketClient connection.
After a successful reconnect, post_reconnection runs after the replacement writer is
installed, buffered messages are drained, and the replacement reader is started. The
callback does not run after the initial connection.
state_sink receives connection state changes. reconnect_replay produces protocol setup
messages that the client sends before buffered application messages after a reconnect.
§Errors
Returns any error connecting to the server.