[][src]Struct actix_ws::Session

pub struct Session { /* fields omitted */ }

A handle into the websocket session.

This type can be used to send messages into the websocket.

Implementations

impl Session[src]

pub async fn text<'_, T>(&'_ mut self, msg: T) -> Result<(), Closed> where
    T: Into<String>, 
[src]

Send text into the websocket

This example is not tested
if session.text("Some text").await.is_err() {
    // session closed
}

pub async fn binary<'_, T>(&'_ mut self, msg: T) -> Result<(), Closed> where
    T: Into<Bytes>, 
[src]

Send raw bytes into the websocket

This example is not tested
if session.binary(b"some bytes").await.is_err() {
    // session closed
}

pub async fn ping<'_, '_>(&'_ mut self, msg: &'_ [u8]) -> Result<(), Closed>[src]

Ping the client

For many applications, it will be important to send regular pings to keep track of if the client has disconnected

This example is not tested
if session.ping(b"").await.is_err() {
    // session is closed
}

pub async fn pong<'_, '_>(&'_ mut self, msg: &'_ [u8]) -> Result<(), Closed>[src]

Pong the client

This example is not tested
match msg {
    Message::Ping(bytes) => {
        let _ = session.pong(&bytes).await;
    }
    _ => (),
}

pub async fn close(
    __arg0: Self,
    reason: Option<CloseReason>
) -> Result<(), Closed>
[src]

Send a close message, and consume the session

All clones will return Err(Closed) if used after this call

This example is not tested
session.close(None).await

Trait Implementations

impl Clone for Session[src]

Auto Trait Implementations

impl !RefUnwindSafe for Session

impl Send for Session

impl Sync for Session

impl Unpin for Session

impl !UnwindSafe for Session

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> Sealed<T> for T where
    T: ?Sized

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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