WebSocket

Edit · View history

WebSocket is a communication protocol that provides full-duplex communication channels over a single Transmission Control Protocol (TCP) connection. It is standardized by the IETF as RFC 6455 and is commonly used in modern web applications for real-time data exchange, such as live chat, online gaming, and financial tickers.

History

The WebSocket Protocol was developed as a solution to the limitations of HTTP for real-time bidirectional communication. Prior to its introduction, techniques such as long polling and server-sent events were used to simulate real-time updates, but they suffered from overhead and latency. The protocol was first proposed by Ian Hickson in 2008 as part of the HTML5 specification and later standardized by the IETF in 2011. Major browser support arrived with Google Chrome 4, Firefox 4, and Internet Explorer 10.

Technical Overview

WebSocket uses a handshake mechanism that upgrades an HTTP connection to a WebSocket connection. Once established, data frames can be sent in either direction with low overhead. The protocol supports both text and binary messages and includes built-in masking for client-to-server frames to prevent cache poisoning. WebSocket operates on TCP port 80 (or 443 for secure WebSocket, wss://). The handshake involves an HTTP Upgrade header and a Sec-WebSocket-Key exchange.

Features

Use Cases

WebSocket is widely used in real-time web applications ranging from collaborative editing tools (e.g., Etherpad) to live sports scoreboards, WebRTC signaling, and Internet of Things (IoT) device communication. Many Node.js frameworks, including Socket.IO and ws, provide WebSocket abstractions.