WebRTC & WebSockets

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

See the section bibliography for the reference material consulted while preparing these pages.

This section teaches how to build three kinds of real-time web application: a chat application, a videoconference application and a multiplayer browser game. It is written for web and backend developers who know HTTP and JavaScript and now need persistent connections, peer-to-peer media or low-latency state synchronisation, and who want to compare several server stacks on equal terms. Every concept has its own page with detailed explanations and runnable examples, and every example is followed by a link to the official documentation it derives from.

Versions and standards were re-checked on 2026-10-24 (the first survey was done on 2026-10-22). The baseline is: WHATWG WebSockets living standard with RFC 6455, RFC 7692, RFC 8441 and RFC 9220; WebSocketStream shipped only in Chromium 124 and later and not on a standards track; WebTransport as a W3C Candidate Recommendation Snapshot of 2026-07-30, supported in Safari 26.4 and later; the W3C WebRTC 1.0 Recommendation (2025-03-13 edition) with JSEP in RFC 9429 and WHIP in RFC 9725 (WHEP is still an Internet-Draft); mediasoup 3.31.0, LiveKit 1.13.10, Janus 1.4.3, Pion 4.2.25, aiortc 1.15.0, coturn 4.18.0 and eturnal 1.12.3; ejabberd 26.09, Prosody 13.0.7, Openfire 5.1.2 and MongooseIM 6.10.0; ASP.NET Core 10.0.13 (LTS) with .NET 11 still in release-candidate state; socket.io 4.8.4 and python-socketio 5.17.0; uWebSockets.js v20.71.0; channels 4.3.2; Spring Framework 7.0.10 and Spring Boot 4.1.2; Atmosphere 4.0.76; Swoole 6.2.3 and OpenSwoole 26.2.0; and Laravel Reverb 1.12.0 on Laravel 13. Each page restates the versions it was written against.

The three scenarios

Every page uses one of three original scenarios, so that the stacks and techniques can be compared on the same problem.

  • Chatterbox is a chat application with rooms (public, private and direct messages), presence, typing indicators, delivery and read receipts, paginated history, edits, reactions, attachments, moderation and offline catch-up. All server-stack pages implement the same JSON wire protocol (an envelope with v, type, id, room, ts and payload), so one browser client can talk to every server. An XMPP variant offers the same features on Prosody or ejabberd.

  • Huddle is a videoconference application with 1:1 calls and rooms, a lobby, mute and camera toggles, device switching, screen sharing, active-speaker detection, chat over a data channel, recording and optional end-to-end encryption. It uses a WebSocket signalling server, a mesh mode for up to four participants, an SFU mode with mediasoup, a LiveKit variant and coturn with ephemeral credentials.

  • Pixel Arena is a multiplayer browser game with an authoritative server, a fixed tick loop, snapshots, client-side prediction, reconciliation, interpolation, lag compensation and unreliable data channels, plus a Colyseus variant and a binary snapshot encoding compared with JSON.

Architecture map: Chatterbox, Pixel Arena and Huddle browsers connect to an XMPP server, WebSocket servers and a game server, an SFU and a TURN relay, with a Redis backplane and a signalling service

Reading paths

I want to build a chat app. Start with Real-Time Web Overview, The WebSocket Protocol and Message Design and Serialization. Pick a server with Choosing a WebSocket Stack and its stack page, then read Chat Architecture, Presence, Typing and Receipts and History, Offline Delivery and Moderation before the end-to-end Building a Chat App. If you prefer a federated, standards-based protocol, take the XMPP Fundamentals path instead.

I want to build a multiplayer game. Start with The WebSocket Protocol, Data Channels and Multiplayer Game Architecture, continue with Latency Compensation and Game Servers and Colyseus, and finish with the end-to-end Building a Multiplayer Game.

Whatever you build, finish with the Production pages, starting with Authentication and Authorization and Security, and use the Comparison & Decision Guide and the Cheat Sheet (PDF) as quick references.

mindmap root((WebRTC and WebSockets)) Foundations Transports and latency WebSocket protocol Browser API SSE and long polling Message design Reconnection WebTransport WebSocket servers Socket.IO uWebSockets.js Django Channels SignalR Spring WebFlux Atmosphere Swoole Laravel Reverb WebRTC Capture and screen sharing Peer connections and SDP ICE STUN TURN Data channels SFUs and media servers End-to-end encryption XMPP Fundamentals and servers Browser clients Chat XEPs OMEMO and Jingle Building applications Chat Videoconference Multiplayer game Production Security Scaling Observability Testing

What’s covered

Foundations

The protocols and browser APIs underneath every real-time application.

Page What it covers

Real-Time Web Overview

Latency budgets, the three application types and the transports compared: polling, long polling, SSE, WebSocket, WebRTC, WebTransport and XMPP.

Networking Fundamentals

TCP and UDP, HTTP/1.1, HTTP/2, HTTP/3 and QUIC, TLS, NAT, ports and proxies as they matter to real-time apps.

The WebSocket Protocol

RFC 6455 handshake, framing, masking, opcodes, ping and pong, close codes, subprotocols, permessage-deflate, and WebSocket over HTTP/2 and HTTP/3.

The Browser WebSocket API

The WHATWG WebSocket API, its events, bufferedAmount, binaryType, and WebSocketStream with feature detection.

Server-Sent Events and Long Polling

EventSource, the text/event-stream format, Last-Event-ID, long polling and when they beat WebSockets.

Message Design and Serialization

The Chatterbox JSON envelope shared by every server page, client-generated IDs, and JSON versus binary encodings.

Connection Lifecycle, Heartbeats and Reconnection

Reconnect with backoff and jitter, heartbeats against idle timeouts, and resuming a session.

WebTransport and Media over QUIC

The WebTransport API, its standards status, browser support and Media over QUIC as an emerging specification.

WebSocket Servers

The same Chatterbox protocol implemented on eight server stacks.

Page What it covers

Choosing a WebSocket Stack

A comparison of the eight server stacks and the other WebSocket pages on this site, with a decision flow.

Socket.IO (Node.js)

The Node.js server and browser client: rooms, namespaces, acknowledgements, connection state recovery and the Redis adapter.

Socket.IO Protocol and Clients

Engine.IO and Socket.IO protocols, transports and clients in other languages.

python-socketio

The Python Socket.IO server on ASGI and WSGI, and the Redis client manager.

uWebSockets.js

The uWebSockets.js server: behaviours, built-in pub/sub, backpressure, limits and licensing.

Django Channels

Chat, presence and game-loop patterns built on top of the existing Channels reference.

SignalR

ASP.NET Core SignalR hubs, groups, streaming, reconnect, authentication and scale-out.

Spring WebFlux WebSockets

Reactor handlers, broadcasting with Sinks, security and testing, contrasted with Spring MVC STOMP.

Atmosphere

The Atmosphere 4 framework: managed services, broadcasters, transport fallback and clustering.

Swoole

The Swoole WebSocket server: process model, coroutines, shared state and OpenSwoole differences.

Laravel Reverb

The Reverb server and Echo client for chat, presence and game use, and scaling.

WebRTC

Capture, peer connections, NAT traversal, data channels and media servers.

Page What it covers

WebRTC Architecture

How capture, signalling, ICE, DTLS-SRTP and the browser APIs fit together.

Media Capture and Devices

getUserMedia, constraints, device enumeration and switching.

Screen Sharing

getDisplayMedia, its options and limits.

Peer Connections and SDP

RTCPeerConnection, JSEP, transceivers and an SDP walkthrough.

Signaling and Perfect Negotiation

A WebSocket signalling server and the perfect negotiation pattern.

ICE, STUN and TURN

NAT traversal, candidates, ephemeral TURN credentials, coturn and eturnal.

Data Channels

Data channel options for chat and games, flow control and file transfer.

Codecs, Simulcast and SVC

Codec negotiation, simulcast encodings and scalable video coding.

Stats, Quality and Bandwidth

getStats, quality metrics and bandwidth estimation.

Recording and Media Processing

MediaRecorder, insertable streams and processing media in the browser.

End-to-End Encryption

Encoded transforms, SFrame and key management through an SFU.

Topologies: Mesh, SFU and MCU

Comparing mesh, SFU and MCU topologies.

mediasoup

The mediasoup SFU: workers, routers, transports, producers and consumers.

LiveKit

The LiveKit SFU, its SDKs, tokens and deployment.

Janus and Jitsi

The Janus gateway and the Jitsi Meet stack.

Pion and aiortc

Building WebRTC peers in Go with Pion and in Python with aiortc.

WHIP, WHEP and Live Streaming

Ingest and playback over WebRTC and the contrast with HLS and DASH.

XMPP

The federated chat protocol, its servers, browser clients and chat extensions.

Page What it covers

XMPP Fundamentals

Architecture, JIDs, streams and the three stanzas.

XMPP Servers

ejabberd, Prosody, Openfire and MongooseIM with Compose files.

XMPP in the Browser

XMPP over WebSocket (RFC 7395), BOSH, Strophe.js and @xmpp/client.

XMPP Chat Features

MUC, MAM, Carbons, Stream Management, receipts, markers, corrections, reactions, HTTP upload and push.

Converse.js

Embedding and customizing the Converse.js web client.

OMEMO Encryption

End-to-end encryption in XMPP with OMEMO.

Jingle Calls and Jitsi

Jingle signalling for calls and how Jitsi Meet uses XMPP.

Building Applications

Architecture and end-to-end builds of the three scenarios.

Page What it covers

Chat Architecture

Components, data model and message flow of a chat system.

Presence, Typing and Receipts

Presence, typing indicators and delivery and read receipts.

History, Offline Delivery and Moderation

History pagination, offline catch-up and moderation.

Building a Chat App

The end-to-end Chatterbox build.

Videoconference Architecture

Rooms, signalling, topologies and media services for a videoconference.

Building a Videoconference App

The end-to-end Huddle build.

Multiplayer Game Architecture

Authoritative servers, tick loops and snapshots.

Latency Compensation

Client-side prediction, reconciliation, interpolation and lag compensation.

Game Servers and Colyseus

Game server frameworks, with Colyseus.

Building a Multiplayer Game

The end-to-end Pixel Arena build.

Production

Authentication, security, scaling, observability, testing and capacity.

Page What it covers

Authentication and Authorization

Tokens, tickets, cookies and per-message authorization.

Security

Origin checks, CSWSH, limits, wss, TURN abuse and SRTP.

Scaling WebSockets

Sticky sessions and backplanes.

Proxies, Load Balancers and Deployment

nginx, ingress and load balancer settings.

Scaling WebRTC and TURN

Scaling SFUs and TURN servers.

Observability

Metrics, logs and traces for real-time systems.

Testing Real-Time Apps

Unit, integration and browser tests.

Load Testing and Capacity Planning

Load testing tools and capacity planning.

Mobile and Native Clients

Mobile and native clients for real-time backends.

Reference

Page What it covers

Comparison & Decision Guide

Transports, server stacks, topologies and XMPP versus a custom protocol, with recommendations by application type.

Cheat Sheet (PDF)

A one-page summary of every concept in this section.

This section documents the real-time angle only. The pages below cover the rest of each framework or technology, and the section links to them instead of repeating them.

Topic Pages

SignalR

ASP.NET Core SignalR and ASP.NET MVC SignalR 2, the short overviews.

Django

Django Channels and WebSockets, the detailed Channels reference.

Laravel and PHP

Broadcasting and Reverb and Octane and Performance (Swoole and OpenSwoole drivers).

Node.js and NestJS

Node.js WebSockets and Server-Sent Events and NestJS WebSockets.

Spring and Thymeleaf

Thymeleaf: Server-Sent Events and WebSockets for Spring MVC.

Other framework pages

JSF WebSocket push, Quarkus WebSockets, Axum WebSockets, Axum SSE and streaming, FastAPI WebSockets, Tornado WebSockets, Vapor WebSockets and Flask streaming and SSE.

AI uses of the same technologies

WebRTC data channels with aiortc, XMPP bots, Streaming chat APIs, LiveKit Agents, Realtime APIs and Telephony with Asterisk and SIP.

Messaging and Redis

Messaging (Kafka, RabbitMQ and protocols) and Redis as backplanes and brokers.

Operations

Docker, Kubernetes and JMeter for containers, ingress settings and load testing.

Security

What is CORS? and OAuth Reference.

Video streaming

Video playback and streaming and Video streaming on the backend for HLS and DASH.

Bibliography

Every source below is the official site, repository or documentation page of the library, service or standard it supports. Versions, release status and draft status change often in this area, so check the linked page for the current state before you rely on a version or status stated in this section.

Books and long-form guides

The following freely available or publisher-hosted works were consulted for structure and concepts. They are not the primary source for any code example; where they differ from the official documentation, the official documentation wins.

Additional IETF specifications

RFCs and Internet-Drafts cited by individual pages for transport, security, real-time media and XMPP details.

Open-source projects and packages

Repositories and package registry pages of the libraries, servers and clients the examples use.

Other official documentation and articles

Individual documentation pages, specifications and articles cited by pages, each from the official site of its subject.