All skills

Databases & Realtime

WebSockets

Overview

WebSocket is a computer communications protocol, providing a bidirectional communication channel over a single Transmission Control Protocol (TCP) connection. The protocol was standardized by the IETF as RFC 6455 in 2011. The current specification allowing web applications to use this protocol is known as WebSockets. It is a living standard maintained by the WHATWG and a successor to The WebSocket API from the W3C.

Read more

How it works

js
const ws = new WebSocket("wss://example.com");
ws.onmessage = (e) => console.log(e.data);
ws.send("hello");

The flow

Step by step, from source to running.

  1. 1Client sends an HTTP Upgrade
  2. 2Server switches protocols (101)
  3. 3Full-duplex channel stays open
  4. 4Both sides push frames anytime

Links

More in Databases & Realtime