The web
WebSocket
One connection kept open after an HTTP upgrade, where either side can send a message at any moment.
A client sends an ordinary HTTP request with Upgrade: websocket and Connection: Upgrade, and the server answers
101 Switching Protocols. From then on the connection carries frames: a small header (2 to 14 bytes) and the data.
Frames from a client are masked with four random bytes, to keep proxies from misreading them, not for secrecy;
wss:// adds TLS for that. Upgrade and Connection are hop by hop, so every proxy has to pass them on by choice. Quiet
connections get closed, so ping and pong frames keep them alive. For data that only flows from server to
client, server-sent events do the job over plain HTTP.
Read next
- HTTP The web's request and response protocol: plain text over TCP unless wrapped in TLS.
- TCP Reliable, ordered byte streams between programs: handshake, acknowledgements, retransmission.
- TLS and certificates Encryption plus proof of identity: the server shows a certificate for the name, signed by a trusted authority.
- Load balancer One address in front of many servers, spreading connections between them and skipping the unhealthy.