Expand description
WebSocket, by hand: the handshake and the frames of RFC 6455, and nothing else.
There is no dependency here for the same reason there is none for base64 or for
percent-encoding: what this server needs of the protocol is a handshake, text frames it
writes, a ping it writes and a close it writes, and that is less code than the seam an
async runtime would introduce into a synchronous server. Socket.IO would be a second
protocol on top of this one, with its own framing, its own reconnection semantics and
its own client to ship, in exchange for nothing this control plane needs.
What is deliberately absent is reading. The server this crate runs is
[tiny_http], whose upgrade hands over one Read + Write value that cannot be split;
a reader thread blocking on it would have to hold the same lock the writer needs. So
the stream this module writes is one-way by design: everything a client wants to say —
which executions to follow, and from which sequence — it says in the request target,
and the server ignores whatever the client sends afterwards. A client that goes away is
noticed by a non-blocking look at the connection’s socket on each quiet interval, which
drains and drops what the client sent (super::events::LOOK), and failing that by the
next write failing, which the heartbeat guarantees will happen.
Enums§
- Handshake
- What a handshake needs from the request, or why it cannot be done.
- Opcode
- The opcodes this server writes.
Constants§
- MAX_
FRAME_ BYTES - The largest frame this server writes in one piece.
Functions§
- accept_
for - The
Sec-WebSocket-Acceptvalue for a client key. - frame
- One unfragmented frame, from the server, unmasked as RFC 6455 requires of a server.
- handshake
- Read the handshake headers and compute the answer.
- is_
upgrade - Is this request asking to become a WebSocket?
- sha1
- SHA-1 of a byte string, for the one thing RFC 6455 specifies it for.
- write_
close - Write a close frame carrying a status code and a reason, then flush.
- write_
ping - Write a ping with no payload.
- write_
text - Write one text frame, refusing a payload over
MAX_FRAME_BYTES.