Struct engineioxide::socket::Socket

source ·
pub struct Socket<D>
where D: Default + Send + Sync + 'static,
{ pub id: Sid, pub protocol: ProtocolVersion, pub data: D, pub req_parts: Parts, /* private fields */ }
Expand description

A Socket represents a client connection to the server. It is agnostic to the TransportType.

It handles :

  • the packet communication between with the Engine and the user defined Handler.
  • the user defined Data bound to the socket.
  • the heartbeat job that verify that the connection is still up by sending packets periodically.

Fields§

§id: Sid

The socket id

§protocol: ProtocolVersion

The protocol version used by the socket

§data: D

User data bound to the socket

§req_parts: Parts

Http Request data used to create a socket

Implementations§

source§

impl<D> Socket<D>
where D: Default + Send + Sync + 'static,

source

pub fn transport_type(&self) -> TransportType

Returns the current TransportType of the Socket

source

pub fn emit(&self, msg: String) -> Result<(), TrySendError<String>>

Emits a message to the client.

If the transport is in websocket mode, the message is directly sent as a text frame.

If the transport is in polling mode, the message is buffered and sent as a text frame to the next polling request.

⚠️ If the buffer is full or the socket is disconnected, an error will be returned with the original data

source

pub fn close(&self, reason: DisconnectReason)

Immediately closes the socket and the underlying connection. The socket will be removed from the Engine and the Handler will be notified.

source

pub fn is_closed(&self) -> bool

Returns true if the socket is closed It means that no more packets can be sent to the client

source

pub async fn closed(&self)

Wait for the socket to be fully closed

source

pub fn emit_binary(&self, data: Vec<u8>) -> Result<(), TrySendError<Vec<u8>>>

Emits a binary message to the client.

If the transport is in websocket mode, the message is directly sent as a binary frame.

If the transport is in polling mode, the message is buffered and sent as a text frame encoded in base64 to the next polling request.

⚠️ If the buffer is full or the socket is disconnected, an error will be returned with the original data

Trait Implementations§

source§

impl<D: Default + Send + Sync + 'static> Debug for Socket<D>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<D> !RefUnwindSafe for Socket<D>

§

impl<D> Send for Socket<D>

§

impl<D> Sync for Socket<D>

§

impl<D> Unpin for Socket<D>
where D: Unpin,

§

impl<D> !UnwindSafe for Socket<D>

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more