WebSockets

Introduction

WebSockets are an advanced communication protocol that enables two-way, real-time communication between a client (like a web browser) and a server over a single, long-lived TCP connection.

Standard HTTP (the protocol web browsers use to fetch web pages) works on a request-response model. The client requests information, and the server responds. If the server has new information for the client (like a new chat message or a stock price update), the client has to constantly ask the server ("poll") if there's anything new. This is inefficient, creates latency, and uses unnecessary resources (repeated requests, headers, connection setups/teardowns).

WebSockets were designed to solve this problem for applications needing real-time interaction.

How it Works

Advantages

Common Use Cases