Glossary termProtocol

WebSocket

Also known as: WebSockets

Communication protocol that provides a persistent, two-way channel between a web browser and a server over a single TCP connection.

WebSocket is a protocol that keeps a connection open between a client, typically a web browser, and a server, so that either side can send messages at any time. Ordinary HTTP follows a request-and-response pattern: the browser asks, the server answers and the exchange is over. A WebSocket connection starts as an HTTP request asking to upgrade the connection; once the server agrees, the same underlying TCP connection carries lightweight messages in both directions for as long as it stays open, using the ws and wss URL schemes.

The Internet Engineering Task Force standardized the protocol as RFC 6455 in 2011, and browsers expose it through a JavaScript API that lets pages open connections, send messages and react to incoming ones. Before WebSocket, sites simulated real-time updates with techniques such as long polling, in which the browser repeatedly makes requests that the server holds open until data is available, wasting resources and adding delay. Server frameworks in most languages support the protocol, and libraries add features such as automatic reconnection.

Typical uses include chat and messaging, multiplayer browser games, collaborative editors that show other people's changes instantly, live dashboards, financial tickers and notifications. Persistent connections bring operational challenges: servers must hold many connections open at once; load balancers and proxies must support them; and applications need reconnection logic for dropped links. Security requires care too. Connections should use the encrypted wss scheme and every message should be validated like any other input, while servers should check the origin of connection requests to prevent cross-site hijacking. Server-sent events are a simpler alternative for one-way streams.

Key points

  • WebSocket keeps a single connection open so that client and server can send messages at any time.
  • Connections begin with an HTTP upgrade request and then carry lightweight bidirectional messages.
  • The protocol was standardized as RFC 6455 in 2011, replacing workarounds such as long polling.
  • Servers should use encrypted wss connections, check request origins and validate every incoming message.

Related entries

Glossary term

HTTP

ProgrammingCybersecurity

Stateless request-response protocol that web browsers, servers and other clients use to request and transfer resources such as web pages and data.

Technology

JavaScript

Programming

High-level programming language of the web, created at Netscape in 1995, that runs in every major browser and on servers through runtimes like Node.js.

Glossary term

Programming approach that lets a program start long-running operations, such as network requests, and continue other work until the results arrive.

Glossary term

Event Loop

Programming

Programming construct that repeatedly waits for events, such as user input or completed network requests, and dispatches each to its handler.

Glossary term

GraphQL

Programming

Query language and runtime for APIs that lets clients request exactly the data they need from a server in a single, strongly typed query.

Glossary term

Device or software that distributes incoming network traffic across multiple servers to improve capacity, responsiveness and availability.

Organization

Open standards organization that develops the technical specifications for core internet protocols and publishes them as Requests for Comments.

Glossary term

Cross-Origin Resource Sharing

ProgrammingCybersecurity

Browser security mechanism that uses HTTP headers to let a server state which other websites may read its responses through scripts.

Referenced by

Other entries that discuss or point to WebSocket.