WebSocket and WebSocketStream

A WebSocket (RFC 6455, 2011) is a persistent two-way connection: after an HTTP Upgrade: websocket request and a 101 Switching Protocols reply, either side sends text or binary messages at any time. It is Baseline Widely available (since January 2018). The client below talks to a Node echo server built with the ws package: socket.on('message', (m) => socket.send('echo: ' + m)).

A WebSocket clientJavaScript
const socket = new WebSocket('ws://localhost:8093/');   // use wss:// in production
socket.onopen = () => socket.send('hello');
socket.onmessage = ({ data }) => {
  console.log('message:', data);
  socket.close(1000, 'done');
};
socket.onclose = ({ code, wasClean }) => console.log('closed', code, wasClean);
Output
message: echo: hello
closed 1000 true

send() buffers without limit (watch bufferedAmount) and nothing reconnects for you. WebSocketStream, Chromium-only since version 124, exposes readable and writable streams with backpressure after await wss.opened. Socket.IO 24,482 adds rooms and reconnection, but its protocol is not plain WebSocket.