pub struct WebSocketWriteHalf { /* private fields */ }
Expand description
The write half of a WebSocket connection, generated from WebSocket::split()
.
This half can only send frames.
Implementations§
Source§impl WebSocketWriteHalf
impl WebSocketWriteHalf
Sourcepub async fn flush(&mut self) -> Result<(), WebSocketError>
pub async fn flush(&mut self) -> Result<(), WebSocketError>
Flushes incoming events from the read half. If the read half received a Ping frame,
a Pong frame will be sent. If the read half received a Close frame,
an echoed Close frame will be sent and the WebSocket will close.
See the documentation on the WebSocket
type for more details
about events.
Sourcepub async fn send_text(&mut self, payload: String) -> Result<(), WebSocketError>
pub async fn send_text(&mut self, payload: String) -> Result<(), WebSocketError>
Sends a Text frame over the WebSocket connection, constructed
from passed arguments. continuation
will be false
and fin
will be true
.
To use a custom continuation
or fin
, construct a Frame
and use
WebSocketWriteHalf::send()
.
This method will flush incoming events.
See the documentation on the WebSocket
type for more details
about events.
Sourcepub async fn send_binary(
&mut self,
payload: Vec<u8>,
) -> Result<(), WebSocketError>
pub async fn send_binary( &mut self, payload: Vec<u8>, ) -> Result<(), WebSocketError>
Sends a Binary frame over the WebSocket connection, constructed
from passed arguments. continuation
will be false
and fin
will be true
.
To use a custom continuation
or fin
, construct a Frame
and use
WebSocketWriteHalf::send()
.
This method will flush incoming events.
See the documentation on the WebSocket
type for more details
about events.
Sourcepub async fn shutdown(&mut self) -> Result<(), WebSocketError>
pub async fn shutdown(&mut self) -> Result<(), WebSocketError>
Shuts down the WebSocket connection without sending a Close frame.
It is recommended to use the close()
method instead.
Sourcepub async fn close(
&mut self,
payload: Option<(u16, String)>,
) -> Result<(), WebSocketError>
pub async fn close( &mut self, payload: Option<(u16, String)>, ) -> Result<(), WebSocketError>
Sends a Close frame over the WebSocket connection, constructed from passed arguments, and closes the WebSocket connection.
As per the WebSocket protocol, the server should send a Close frame in response upon receiving a Close frame. Although the write half will be closed, the server’s echoed Close frame can be read from the still open read half.
This method will flush incoming events.
See the documentation on the WebSocket
type for more details
about events.