Struct tungstenite::protocol::WebSocketContext [−][src]
pub struct WebSocketContext { /* fields omitted */ }
Expand description
A context for managing WebSocket stream.
Implementations
Create a WebSocket context that manages a post-handshake stream.
pub fn from_partially_read(
part: Vec<u8>,
role: Role,
config: Option<WebSocketConfig>
) -> Self
pub fn from_partially_read(
part: Vec<u8>,
role: Role,
config: Option<WebSocketConfig>
) -> Self
Create a WebSocket context that manages an post-handshake stream.
Change the configuration.
Read the configuration.
Check if it is possible to read messages.
Reading is impossible after receiving Message::Close
. It is still possible after
sending close frame since the peer still may send some data before confirming close.
Check if it is possible to write messages.
Writing gets impossible immediately after sending or receiving Message::Close
.
Read a message from the provided stream, if possible.
This function sends pong and close responses automatically. However, it never blocks on write.
Send a message to the provided stream, if possible.
WebSocket will buffer a configurable number of messages at a time, except to reply to Ping
and Close requests. If the WebSocket’s send queue is full, SendQueueFull
will be returned
along with the passed message. Otherwise, the message is queued and Ok(()) is returned.
Note that only the last pong frame is stored to be sent, and only the most recent pong frame is sent if multiple pong frames are queued.
Flush the pending send queue.
Close the connection.
This function guarantees that the close frame will be queued.
There is no need to call it again. Calling this function is
the same as calling write(Message::Close(..))
.