Glossary

WebSocket

WEB-sok-it

A protocol that keeps a two-way connection open between browser and server for real-time data.

WebSocket is a protocol that keeps a single connection open between the browser and the server, so both sides can send messages at any time.

How it works

A normal HTTP request is one question, one answer. A WebSocket starts as HTTP, then upgrades into a connection that stays open.

const ws = new WebSocket('wss://example.com/chat');
ws.onmessage = (event) => console.log(event.data);
ws.send('Hello!');

Why it matters

WebSockets power chat apps, live notifications, multiplayer games and collaborative editors. If only the server needs to push updates, Server-Sent Events are simpler. That’s how most AI chat apps stream answers from an LLM, token by token.

Related: Webhook, for events between servers.