---
obj: concept
wiki: https://en.wikipedia.org/wiki/WebSocket
rfc: https://datatracker.ietf.org/doc/html/rfc6455
website: https://websockets.spec.whatwg.org
---

# WebSocket
WebSockets provide a bidirectional communication channel over a single, long-lived connection. This enables real-time, low-latency data exchange between a client and a server.

## WebSocket Protocol
### 1. **WebSocket Handshake:**
The WebSocket handshake is an [HTTP](HTTP.md)-based protocol that establishes a connection between the client and server. Once established, the connection switches to the WebSocket protocol.
### 2. **WebSocket Frames:**
Messages in WebSockets are sent as frames. Frames can be text, binary, or control frames used for connection management.

## Usage and Benefits
### 1. **Real-Time Applications:**
WebSockets are ideal for real-time applications like live chats, online gaming, financial trading, and collaborative tools.
### 2. **Reduced Latency:**
The persistent connection minimizes latency compared to traditional [HTTP](HTTP.md), making WebSockets suitable for applications requiring low-latency communication.
### 3. **Efficient Data Transfer:**
WebSockets use a compact binary frame format, reducing the overhead associated with text-based protocols.