Struct engineioxide::socket::Socket

source ·
pub struct Socket<H>where
    H: EngineIoHandler + ?Sized,{
    pub sid: Sid,
    pub protocol: ProtocolVersion,
    pub tx: Sender<SendPacket>,
    pub data: H::Data,
    pub req_data: Arc<SocketReq>,
    /* private fields */
}
Expand description

A Socket represents a 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§

§sid: Sid

The socket id

§protocol: ProtocolVersion

The protocol version used by the socket

§tx: Sender<SendPacket>§data: H::Data

User data bound to the socket

§req_data: Arc<SocketReq>

Http Request data used to create a socket

Implementations§

source§

impl<H> Socket<H>where H: EngineIoHandler + ?Sized,

source

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

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

source

pub fn close(&self)

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 emit_binary(&self, data: Vec<u8>) -> Result<(), Error>

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

Auto Trait Implementations§

§

impl<H> !RefUnwindSafe for Socket<H>

§

impl<H> Send for Socket<H>

§

impl<H> Sync for Socket<H>

§

impl<H> Unpin for Socket<H>where <H as EngineIoHandler>::Data: Unpin,

§

impl<H> !UnwindSafe for Socket<H>

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,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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> Instrument for T

source§

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

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

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

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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 Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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