pub struct WebSocket<Stream> {
pub stream: Stream,
pub max_payload_len: usize,
/* private fields */
}
Expand description
WebSocket implementation for both client and server
Fields§
§stream: Stream
it is a low-level abstraction that represents the underlying byte stream over which WebSocket messages are exchanged.
max_payload_len: usize
Maximum allowed payload length in bytes.
Default: 16 MB
Implementations§
Source§impl<W> WebSocket<W>where
W: Unpin + AsyncWrite,
impl<W> WebSocket<W>where
W: Unpin + AsyncWrite,
Sourcepub async fn send(&mut self, data: impl Into<Frame<'_>>) -> Result<()>
pub async fn send(&mut self, data: impl Into<Frame<'_>>) -> Result<()>
Send message to a endpoint.
Sourcepub async fn close<T>(self, reason: T) -> Result<()>
pub async fn close<T>(self, reason: T) -> Result<()>
- The Close frame MAY contain a body that indicates a reason for closing.
Sourcepub async fn send_ping(&mut self, data: impl AsRef<[u8]>) -> Result<()>
pub async fn send_ping(&mut self, data: impl AsRef<[u8]>) -> Result<()>
A Ping frame may serve either as a keepalive or as a means to verify that the remote endpoint is still responsive.
It is used to send ping frame.
§Example
let writer = Vec::new();
let mut ws = WebSocket::client(writer);
ws.send_ping("Hello!").await;
Sourcepub async fn send_pong(&mut self, data: impl AsRef<[u8]>) -> Result<()>
pub async fn send_pong(&mut self, data: impl AsRef<[u8]>) -> Result<()>
A Pong frame sent in response to a Ping frame must have identical “Application data” as found in the message body of the Ping frame being replied to.
A Pong frame MAY be sent unsolicited. This serves as a unidirectional heartbeat. A response to an unsolicited Pong frame is not expected.
Trait Implementations§
Auto Trait Implementations§
impl<Stream> Freeze for WebSocket<Stream>where
Stream: Freeze,
impl<Stream> RefUnwindSafe for WebSocket<Stream>where
Stream: RefUnwindSafe,
impl<Stream> Send for WebSocket<Stream>where
Stream: Send,
impl<Stream> Sync for WebSocket<Stream>where
Stream: Sync,
impl<Stream> Unpin for WebSocket<Stream>where
Stream: Unpin,
impl<Stream> UnwindSafe for WebSocket<Stream>where
Stream: UnwindSafe,
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