pub struct WebSocket {
pub url: String,
/* private fields */
}Expand description
W3C WebSocket client interface supporting ws:// and TLS wss://.
Fields§
§url: StringImplementations§
Source§impl WebSocket
impl WebSocket
Sourcepub fn connect(url: &str) -> Result<WebSocket, WsError>
pub fn connect(url: &str) -> Result<WebSocket, WsError>
Establishes a real RFC 6455 WebSocket connection over plain TCP (ws://) or TLS (wss://).
Sourcepub fn ready_state(&self) -> WsState
pub fn ready_state(&self) -> WsState
Current connection state.
Sourcepub fn send_text(&self, text: &str) -> Result<(), WsError>
pub fn send_text(&self, text: &str) -> Result<(), WsError>
Sends a text message over the WebSocket. If length exceeds DEFAULT_MAX_FRAME_SIZE, it is fragmented.
Sourcepub fn send_binary(&self, data: &[u8]) -> Result<(), WsError>
pub fn send_binary(&self, data: &[u8]) -> Result<(), WsError>
Sends binary data over the WebSocket. If length exceeds DEFAULT_MAX_FRAME_SIZE, it is fragmented.
Sourcepub fn send_text_fragmented(
&self,
text: &str,
chunk_size: usize,
) -> Result<(), WsError>
pub fn send_text_fragmented( &self, text: &str, chunk_size: usize, ) -> Result<(), WsError>
Sends a text message split into multiple frames with given chunk size.
Sourcepub fn send_binary_fragmented(
&self,
data: &[u8],
chunk_size: usize,
) -> Result<(), WsError>
pub fn send_binary_fragmented( &self, data: &[u8], chunk_size: usize, ) -> Result<(), WsError>
Sends binary data split into multiple frames with given chunk size.
Sourcepub fn send_payload_fragmented(
&self,
opcode: WsOpcode,
payload: &[u8],
chunk_size: usize,
) -> Result<(), WsError>
pub fn send_payload_fragmented( &self, opcode: WsOpcode, payload: &[u8], chunk_size: usize, ) -> Result<(), WsError>
Helper to send payload in fragmented RFC 6455 frames.
Sourcepub fn close(&self, code: u16, reason: &str) -> Result<(), WsError>
pub fn close(&self, code: u16, reason: &str) -> Result<(), WsError>
Closes the WebSocket connection with status code and reason.
Sourcepub fn ingest_incoming_bytes(&self, buf: &[u8]) -> Result<usize, WsError>
pub fn ingest_incoming_bytes(&self, buf: &[u8]) -> Result<usize, WsError>
Ingests received raw bytes and decodes messages into the internal buffer.
Sourcepub fn poll_message(&self) -> Option<WsMessage>
pub fn poll_message(&self) -> Option<WsMessage>
Pops the next received message from the queue, if any.
Sourcepub fn recv_message_timeout(&self, timeout: Duration) -> Option<WsMessage>
pub fn recv_message_timeout(&self, timeout: Duration) -> Option<WsMessage>
Waits up to timeout for a message to arrive.
Sourcepub fn drain_outgoing_frames(&self) -> Vec<Vec<u8>>
pub fn drain_outgoing_frames(&self) -> Vec<Vec<u8>>
Drains all currently queued outgoing encoded frames.