pub struct WebSocket { /* private fields */ }Expand description
RFC 6455 WebSocket client.
Implementations§
Source§impl WebSocket
impl WebSocket
Sourcepub fn connect(
host: &str,
port: u16,
path: &str,
use_tls: bool,
) -> Result<Self, NetworkError>
pub fn connect( host: &str, port: u16, path: &str, use_tls: bool, ) -> Result<Self, NetworkError>
Open a WebSocket connection to ws://host:port/path (plain) or
wss://host:port/path (TLS).
§Errors
Returns NetworkError::ConnectFailed on failure.
Sourcepub fn send_binary(&self, data: &[u8]) -> Result<(), NetworkError>
pub fn send_binary(&self, data: &[u8]) -> Result<(), NetworkError>
Sourcepub fn receive(&self, max_len: usize) -> Result<WsMessage, NetworkError>
pub fn receive(&self, max_len: usize) -> Result<WsMessage, NetworkError>
Receive one WebSocket message (blocking up to max_len bytes).
§Errors
Returns NetworkError::ReceiveFailed.
Sourcepub unsafe fn set_pong_handler(
&self,
metadata: *mut c_void,
callback: WsPongCallback,
) -> Result<(), NetworkError>
pub unsafe fn set_pong_handler( &self, metadata: *mut c_void, callback: WsPongCallback, ) -> Result<(), NetworkError>
Register a pong handler callback for WebSocket messages.
This registers a callback that will be invoked whenever a pong frame is received.
The callback will receive a crate::FrameworkError if there was an error processing the pong,
or None if the pong was handled successfully.
§Safety
- The callback must be safe to call from the networking dispatch queue.
- The provided metadata must be valid WebSocket protocol metadata.
- The metadata pointer must remain valid while the callback is in use.
§Errors
Returns NetworkError::InvalidArgument if metadata is null.
Sourcepub unsafe fn set_pong_handler_with_context(
&self,
metadata: *mut c_void,
callback: WsPongCallback,
user_info: *mut c_void,
) -> Result<(), NetworkError>
pub unsafe fn set_pong_handler_with_context( &self, metadata: *mut c_void, callback: WsPongCallback, user_info: *mut c_void, ) -> Result<(), NetworkError>
Register a pong handler with user context.
Similar to Self::set_pong_handler but allows passing user context that
will be forwarded to the callback.
§Safety
- The callback must be safe to call from the networking dispatch queue.
- The provided metadata must be valid WebSocket protocol metadata.
- The metadata and
user_infopointers must remain valid while the callback is in use.
§Errors
Returns NetworkError::InvalidArgument if metadata is null.