WebSocket (RFC 6455) — a protocol on top of TCP providing full-duplex bidirectional communication between browser and server. Unlike HTTP, the connection stays open; the server can push without a request. Use-cases: real-time chat, live notifications, multiplayer games, collaborative editing. Handshake via HTTP Upgrade header → switch to ws:// or wss://.
Below: details, example, related terms, FAQ.
Upgrade: websocket + Connection: Upgradeconst ws = new WebSocket('wss://example.com/socket');
ws.onmessage = e => console.log(e.data);
ws.onopen = () => ws.send(JSON.stringify({ type: 'subscribe' }));WebSocket — bidirectional (both send). SSE — one-way (server→client only). SSE is simpler and works over HTTP, WebSocket is faster.
Implement reconnect with exponential backoff. Socket.IO does this automatically.
One Node.js handles 10k+ concurrent WebSockets. For 100k+ — Redis pub/sub between instances or a managed service (Ably, Pusher).