WebSocket

From WikiTech, the free technology encyclopedia

Protocol for two-way web connections (RFC 6455)

3 sources from Internet Engineering Task Force, MDN Web Docs (Mozilla) and WHATWG. Checked by ByteExplained editors on 5 December 2026. How we check facts

WebSocket is a network protocol that lets a client, usually a Web browser, and a server hold a long-lived, two-way conversation over a single connection. It was published by the Internet Engineering Task Force as RFC 6455 in December 2011, written by I. Fette of Google and A. Melnikov of Isode.[1] Its stated aim is to give browser-based applications two-way communication without opening many separate Hypertext Transfer Protocol connections, as older techniques such as long polling did.[1]

Contents
  1. How it works
  2. In web browsers
  3. See also
  4. References

How it works

A WebSocket connection begins as an ordinary HTTP request asking the server to "upgrade" the connection. The client sends a random key; the server combines it with a fixed value, hashes the result and sends it back, proving that it really understood the WebSocket request. A reply with status code 101 means the switch has succeeded.[1] From then on, the two sides exchange messages over the same TCP/IP connection, split into small frames that carry text, binary data or control signals such as ping, pong and close. Frames sent by the client must be scrambled ("masked") with a random key, a rule intended to protect proxies and other equipment along the route. Either side can end the session with a closing handshake.[1]

Addresses use the ws:// scheme, on port 80 by default, or wss:// for connections protected by Transport Layer Security, on port 443.[1]

In web browsers

Web pages use the protocol through the WebSocket programming interface in JavaScript. It lets a page send messages to a server and receive replies without repeatedly polling the server for updates.[2] MDN describes the interface as available across browsers since July 2015, but notes that it does not support backpressure, so a flood of incoming messages can overwhelm a page; it points to the newer WebTransport interface for such cases.[2] The browser interface itself is defined by the WHATWG WebSockets Standard, a living standard created in 2021 from text moved out of the HTML and Fetch standards, which builds on RFC 6455 rather than replacing it.[3]

See also

References

  1. ^ RFC 6455: The WebSocket Protocol. Internet Engineering Task Force. 2011-12-01. datatracker.ietf.org
  2. ^ The WebSocket API (WebSockets). MDN Web Docs (Mozilla). developer.mozilla.org
  3. ^ WebSockets Standard. WHATWG. 2026-11-12. websockets.spec.whatwg.org
Technologies on WikiTech
Internet
Computer networks
All technologies