Struct mio_httpc::WebSocket

source ·
pub struct WebSocket { /* private fields */ }
Expand description

WebSocket interface.

WebSocket does not send pings/pongs automatically or close replies.

If received ping, you should send pong back. You can also just send pong which will not invoke a response. You should send ping periodically as you never know if your connection is actually alive without it.

If WSPacket::Close() returned you should call close and then finish. If you want to initiate close, you should call close and wait for WSPacket::Close(), then call finish. That is the standard way of closing ws connections.

Implementations

True if websocket is established. False if still initiating or closed.

How many bytes are in send buffer waiting to be sent. Does not take into account any send_bin_inplace packets.

For quick comparison with httpc::event response. If cid is none will return false.

If using Option in a struct, you can quickly compare callid from httpc::event. If either is none will return false.

Ping server. Body if present is capped at 125 bytes.

A reply to ping or not. Both are valid. Body if present is capped at 125 bytes.

A reply to close or initiate close. close must be sent by both parties. Body if present is capped at 125 bytes.

Actually close connection. If any other call returns error, you should always call finish afterwards.

Actually close connection and replace self with an empty websocket.

Send text packet. Data gets copied out into an internal buffer, as it must be masked before sending. No bytes will have been sent after calling this. Actual sending is done by recv_packet or perform.

Send binary packet. Data gets copied out into an internal buffer, as it must be masked before sending. No bytes will have been sent after calling this. Actual sending is done by recv_packet or perform.

Send websocket packet. It will create a frame for entire size of pkt slice. It is assumed slice always starts at unsent data. If pkt was not sent completely it will remember how many bytes it has leftover for current packet. You must always use previous result to move pkt slice forward.

If starting from the middle, fin is ignored and will be used to start the next packet.

inplace send will mask pkt directly and send it. This is the most efficient method but leaves pkt scrambled.

You should call this in a loop until you get WSPacket::None.

Perform socket operation.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.