pub struct WebSocketConnection {
pub id: ConnectionId,
/* private fields */
}
Expand description
WebSocket connection wrapper - clean API over tokio-tungstenite
Fields§
§id: ConnectionId
Unique connection identifier
Implementations§
Source§impl WebSocketConnection
impl WebSocketConnection
Sourcepub async fn from_stream<S>(
stream: S,
config: WebSocketConfig,
) -> WebSocketResult<Self>
pub async fn from_stream<S>( stream: S, config: WebSocketConfig, ) -> WebSocketResult<Self>
Create a new WebSocket connection from a TCP stream
Sourcepub async fn send(&self, message: WebSocketMessage) -> WebSocketResult<()>
pub async fn send(&self, message: WebSocketMessage) -> WebSocketResult<()>
Send a message to the WebSocket
Sourcepub async fn send_text<T: Into<String>>(&self, text: T) -> WebSocketResult<()>
pub async fn send_text<T: Into<String>>(&self, text: T) -> WebSocketResult<()>
Send a text message
Sourcepub async fn send_binary<T: Into<Vec<u8>>>(
&self,
data: T,
) -> WebSocketResult<()>
pub async fn send_binary<T: Into<Vec<u8>>>( &self, data: T, ) -> WebSocketResult<()>
Send a binary message
Sourcepub async fn close(&self) -> WebSocketResult<()>
pub async fn close(&self) -> WebSocketResult<()>
Close the connection
Sourcepub async fn close_with_reason(
&self,
code: u16,
reason: String,
) -> WebSocketResult<()>
pub async fn close_with_reason( &self, code: u16, reason: String, ) -> WebSocketResult<()>
Close the connection with a reason
Sourcepub async fn state(&self) -> ConnectionState
pub async fn state(&self) -> ConnectionState
Get the current connection state
Sourcepub async fn metadata(&self) -> ConnectionMetadata
pub async fn metadata(&self) -> ConnectionMetadata
Get connection metadata
Sourcepub async fn set_metadata(&self, key: String, value: String)
pub async fn set_metadata(&self, key: String, value: String)
Update connection metadata
Sourcepub async fn stats(&self) -> ConnectionStats
pub async fn stats(&self) -> ConnectionStats
Get connection statistics
Trait Implementations§
Source§impl Clone for WebSocketConnection
impl Clone for WebSocketConnection
Source§fn clone(&self) -> WebSocketConnection
fn clone(&self) -> WebSocketConnection
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for WebSocketConnection
impl !RefUnwindSafe for WebSocketConnection
impl Send for WebSocketConnection
impl Sync for WebSocketConnection
impl Unpin for WebSocketConnection
impl !UnwindSafe for WebSocketConnection
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
Mutably borrows from an owned value. Read more