What is a WebSocket?

Definition

A WebSocket begins with a web-compatible handshake and then keeps a full-duplex connection open. Both client and server can send messages whenever new information is available instead of creating a separate request for every update.

Real-time systems use WebSockets for market data, chat, dashboards and event streams. Compared with periodic polling, a persistent connection can reduce delay and repeated request overhead, although applications must handle disconnects, authentication, message ordering and recovery.

ELI5

A WebSocket is a network connection that stays open so a browser and server can send messages to each other at any time. It avoids starting a new request whenever fresh information appears.

For example, a chat app can receive a new message immediately through an open WebSocket instead of asking the server every few seconds whether anything changed. The app still needs to handle lost connections, identity checks, message order, and reconnection.

How is a WebSocket different from polling?

A WebSocket keeps a two-way connection open, while polling repeatedly asks the server whether new information is available.

Why do trading bots use WebSockets?

They provide timely market updates and order events without waiting for the next scheduled polling request.

  1. Flat robot hand placing a token beside the words AI Builds a Kalshi Bot
  2. Portrait of Alex Hancock with the headline "One Protocol, Many Clients".
Definition card for WebSocket: What is a WebSocket?

A WebSocket is a persistent two-way network connection that lets a client and server exchange messages with low overhead.