pub struct WebSocketConnection { /* private fields */ }Expand description
An upgraded connection. recv returns the client’s
messages, answering pings and the closing handshake itself; send with
the methods here or a WebSocketSender from sender,
which another thread can use while this one waits in recv.
Implementations§
Source§impl WebSocketConnection
impl WebSocketConnection
Sourcepub fn max_message_size(self, bytes: usize) -> Self
pub fn max_message_size(self, bytes: usize) -> Self
Refuse messages over bytes (default MAX_MESSAGE) with close
code 1009.
Sourcepub fn sender(&self) -> WebSocketSender
pub fn sender(&self) -> WebSocketSender
A sender for this connection, for other threads.
Sourcepub fn close(&self, code: u16, reason: &str) -> Result<(), String>
pub fn close(&self, code: u16, reason: &str) -> Result<(), String>
Start the closing handshake; recv then returns
Ok(None) when the client answers.
Sourcepub fn recv(&mut self) -> Result<Option<Message>, String>
pub fn recv(&mut self) -> Result<Option<Message>, String>
The next message; Ok(None) once the connection closed cleanly
(the closing handshake done, whoever started it). Pings are
answered and pongs dropped on the way. A protocol error — an
unmasked frame, a bad fragment, invalid UTF-8, an oversized message
— closes the connection with the matching code and is returned as
Err, as is the client disappearing without a close frame.