Struct web_socket::WebSocket

source ·
pub struct WebSocket<const SIDE: bool, Stream> {
    pub stream: Stream,
    pub max_payload_len: usize,
    /* private fields */
}
Expand description

WebSocket implementation for both client and server

Fields§

§stream: Stream

it is a low-level abstraction that represents the underlying byte stream over which WebSocket messages are exchanged.

§max_payload_len: usize

maximum allowed payload length in bytes

Implementations§

source§

impl<IO> WebSocket<CLIENT, IO>

source

pub fn client(stream: IO) -> Self

Create a new websocket client instance.

source§

impl<IO> WebSocket<SERVER, IO>

source

pub fn server(stream: IO) -> Self

Create a websocket server instance.

source§

impl<const SIDE: bool, W: Unpin + AsyncWrite> WebSocket<SIDE, W>

source

pub async fn send(&mut self, data: impl Message) -> Result<()>

Send message to a endpoint.

source

pub async fn send_ping(&mut self, data: impl AsRef<[u8]>) -> Result<()>

A Ping frame may serve either as a keepalive or as a means to verify that the remote endpoint is still responsive.

source

pub async fn send_pong(&mut self, data: impl AsRef<[u8]>) -> Result<()>

Sends a pong frame in response to a ping frame received from the WebSocket endpoint.

source

pub async fn flash(&mut self) -> Result<()>

Flushes this output stream, ensuring that all intermediately buffered contents reach their destination.

source

pub async fn close<T>(self, reason: T) -> Result<()>where T: CloseFrame, T::Frame: AsRef<[u8]>,

  • The Close frame MAY contain a body that indicates a reason for closing.
source§

impl<const SIDE: bool, R> WebSocket<SIDE, R>where R: Unpin + AsyncRead,

source

pub async fn recv(&mut self) -> Result<Event>

reads Event from websocket stream.

Trait Implementations§

source§

impl<const SIDE: bool, Stream: Debug> Debug for WebSocket<SIDE, Stream>

source§

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

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

impl<const SIDE: bool, IO> From<IO> for WebSocket<SIDE, IO>

source§

fn from(stream: IO) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<const SIDE: bool, Stream> RefUnwindSafe for WebSocket<SIDE, Stream>where Stream: RefUnwindSafe,

§

impl<const SIDE: bool, Stream> Send for WebSocket<SIDE, Stream>where Stream: Send,

§

impl<const SIDE: bool, Stream> Sync for WebSocket<SIDE, Stream>where Stream: Sync,

§

impl<const SIDE: bool, Stream> Unpin for WebSocket<SIDE, Stream>where Stream: Unpin,

§

impl<const SIDE: bool, Stream> UnwindSafe for WebSocket<SIDE, Stream>where Stream: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<!> for T

const: unstable · source§

fn from(t: !) -> T

Converts to this type from the input type.
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V