Struct engineioxide::socket::Socket
source · pub struct Socket<D>{
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 :
Fields§
§id: SidThe socket id
protocol: ProtocolVersionThe protocol version used by the socket
data: DUser data bound to the socket
req_parts: PartsHttp Request data used to create a socket
Implementations§
source§impl<D> Socket<D>
impl<D> Socket<D>
sourcepub fn transport_type(&self) -> TransportType
pub fn transport_type(&self) -> TransportType
Returns the current TransportType of the Socket
sourcepub fn reserve(&self) -> Result<Permit<'_>, TrySendError<()>>
pub fn reserve(&self) -> Result<Permit<'_>, TrySendError<()>>
Reserve n permits to emit multiple messages and ensure that there is enough
space in the internal chan.
If the internal chan is full, the function will return a TrySendError::Full error.
If the socket is closed, the function will return a TrySendError::Closed error.
sourcepub fn emit(&self, msg: impl Into<Str>) -> Result<(), TrySendError<Str>>
pub fn emit(&self, msg: impl Into<Str>) -> Result<(), TrySendError<Str>>
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
sourcepub fn close(&self, reason: DisconnectReason)
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.
sourcepub fn is_closed(&self) -> bool
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
sourcepub fn emit_binary<B: Into<Bytes>>(
&self,
data: B,
) -> Result<(), TrySendError<Bytes>>
pub fn emit_binary<B: Into<Bytes>>( &self, data: B, ) -> Result<(), TrySendError<Bytes>>
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