What is WebSocket?

WebSocket is a protocol that provides a persistent, two-way (full-duplex) communication channel between a client and server over a single TCP connection. Unlike HTTP request/response, either side can send messages at any time.

A WebSocket connection starts as an HTTP request that is "upgraded" (HTTP 101 Switching Protocols), then stays open for low-latency, real-time data.

Key points

  • Persistent, full-duplex connection — both sides can push data.
  • Starts as an HTTP request upgraded to ws:// or wss://.
  • Lower latency and overhead than repeated HTTP polling.
  • Ideal for real-time features.

Example

GET /chat
Upgrade: websocket
→ HTTP/1.1 101 Switching Protocols

Common uses

  • Chat and messaging apps
  • Live dashboards and notifications
  • Collaborative editing
  • Multiplayer games and live feeds

More terms