Skip to main content

WebSocket

Struct WebSocket 

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

a WebSocket client that never blocks (see the top of this file); dropping it closes it

Implementations§

Source§

impl WebSocket

Source

pub fn connect(url: &str) -> Result<WebSocket, Error>

connect with the default limits

Source

pub fn connect_with(url: &str, o: WsOptions) -> Result<WebSocket, Error>

connect with these limits: Connecting at once, Open once the upgrade is done

Source

pub fn state(&self) -> WsState

where it stands

Source

pub fn send_text(&self, s: &str) -> Result<(), Error>

send a text message (Open only; desktop: queued, Backlog beyond max_unsent)

Source

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

send a binary message (as send_text)

Source

pub fn recv(&self) -> Option<WsMessage>

the next message, or None (never waits)

Source

pub fn close(&self, code: u16, reason: &str)

close with code (1000, 3000-4999) and a reason (at most 123 bytes)

Source

pub fn close_info(&self) -> Option<(u16, String)>

how it ended (code and reason; 1006: without a close frame or never connected); None while it is not Closed

Source

pub fn unsent(&self) -> usize

(desktop) bytes queued by send and not written yet (the browser buffers on its own: 0)

Auto Trait Implementations§

§

impl !RefUnwindSafe for WebSocket

§

impl !UnwindSafe for WebSocket

§

impl Forget for WebSocket

§

impl Freeze for WebSocket
where *const ArcInner<Shared> is !null: Freeze, PhantomData<ArcInner<Shared>>: Freeze,

§

impl Move for WebSocket

§

impl Send for WebSocket
where Arc<Shared>: Send,

§

impl Sync for WebSocket
where Arc<Shared>: Sync,

§

impl Unpin for WebSocket
where Arc<Shared>: Unpin,

§

impl UnsafeUnpin for WebSocket
where *const ArcInner<Shared> is !null: UnsafeUnpin, PhantomData<ArcInner<Shared>>: UnsafeUnpin,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.