Skip to main content

WebSocket

Struct WebSocket 

Source
pub struct WebSocket { /* private fields */ }
Expand description

RFC 6455 WebSocket client.

Implementations§

Source§

impl WebSocket

Source

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.

Source

pub fn send_text(&self, text: &str) -> Result<(), NetworkError>

Send a UTF-8 text message.

§Errors

Returns NetworkError::SendFailed.

Source

pub fn send_binary(&self, data: &[u8]) -> Result<(), NetworkError>

Send a binary message.

§Errors

Returns NetworkError::SendFailed.

Source

pub fn send_ping(&self, payload: &[u8]) -> Result<(), NetworkError>

Send a ping (with optional payload).

§Errors

Returns NetworkError::SendFailed.

Source

pub fn send(&self, data: &[u8], opcode: Opcode) -> Result<(), NetworkError>

Generic send.

§Errors

Returns NetworkError::SendFailed.

Source

pub fn receive(&self, max_len: usize) -> Result<WsMessage, NetworkError>

Receive one WebSocket message (blocking up to max_len bytes).

§Errors

Returns NetworkError::ReceiveFailed.

Source

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.

Source

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_info pointers must remain valid while the callback is in use.
§Errors

Returns NetworkError::InvalidArgument if metadata is null.

Trait Implementations§

Source§

impl Debug for WebSocket

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for WebSocket

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for WebSocket

Source§

impl Sync for WebSocket

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.