WebSockets
TCP based network-protocol that enables bidirectional communication between client (web-browser) and server (WebSocket-Server).
(from 223_Multi-User App)
A WebSocket URI starts with ws: or wss: for a secured connection.
Handshake
Clients request
GET /chat HTTP/1.1
Host: server.example.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
Origin: http://example.com
Sec-WebSocket-Protocol: chat, superchat
Sec-WebSocket-Version: 13
Servers response
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
Sec-WebSocket-Protocol: chat
Sec-WebSocket-Key and Sec-WebSocket-Accept
Sec-WebSocket-Accept adds the Sec-WebSocket-Key to a GUID which is then hashed using SHA1.
Sec-WebSocket-Protocol
This header defines sub-protocols. Common ones are MQTT, WAMP or STOMP. It is also possible to define custom ones (like the ones above).
Implementations
- Rails: Knowledge/test/ActionCable
- ASP.NET: SignalR