Skip to main content

Connection

Struct Connection 

Source
pub struct Connection<S = MaybeTlsStream<TcpStream>> { /* private fields */ }
Expand description

WebSocket connection wrapper around a Tokio Tungstenite stream.

Implementations§

Source§

impl<S> Connection<S>
where S: AsyncRead + AsyncWrite + Unpin,

Source

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

Send a text or binary message.

Source

pub async fn recv(&mut self) -> Result<Message, Error>

Receive the next text or binary message, responding to pings as needed.

Source

pub async fn close(&mut self) -> Result<(), Error>

Close the WebSocket connection gracefully.

Source

pub fn get_ref(&self) -> &S

Borrow the underlying transport stream.

Source

pub fn get_mut(&mut self) -> &mut S

Mutably borrow the underlying transport stream.

Source§

impl<S> Connection<S>

Source

pub fn peer_addr(&self) -> SocketAddr

Return the peer address.

Source

pub fn local_addr(&self) -> SocketAddr

Return the local address.

Source

pub fn is_tls(&self) -> bool

Report whether TLS is in use.

Source

pub fn info(&self) -> ConnectionInfo

Return the full connection metadata snapshot.

Trait Implementations§

Source§

impl<S> WebSocketConnection for Connection<S>
where S: AsyncRead + AsyncWrite + Unpin,

Source§

fn send<'a>( &'a mut self, msg: Message, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'a>>

Send one message.
Source§

fn recv<'a>( &'a mut self, ) -> Pin<Box<dyn Future<Output = Result<Message, Error>> + 'a>>

Receive one message.
Source§

fn close<'a>( &'a mut self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'a>>

Close the connection gracefully.

Auto Trait Implementations§

§

impl<S = MaybeTlsStream<TcpStream>> !Freeze for Connection<S>

§

impl<S = MaybeTlsStream<TcpStream>> !RefUnwindSafe for Connection<S>

§

impl<S> Send for Connection<S>
where S: Send,

§

impl<S> Sync for Connection<S>
where S: Sync,

§

impl<S> Unpin for Connection<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for Connection<S>
where S: UnsafeUnpin,

§

impl<S = MaybeTlsStream<TcpStream>> !UnwindSafe for Connection<S>

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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

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

Source§

fn vzip(self) -> V