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 :
Fields§
§sid: SidThe socket id
protocol: ProtocolVersionThe protocol version used by the socket
tx: Sender<SendPacket>§data: H::DataUser 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,
impl<H> Socket<H>where H: EngineIoHandler + ?Sized,
sourcepub fn emit(&self, msg: String) -> Result<(), Error>
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
sourcepub fn close(&self)
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.
sourcepub fn emit_binary(&self, data: Vec<u8>) -> Result<(), Error>
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