# Broadcasting and Rooms

A ws server broadcasts by sending one message to every open client in wss.clients, greets a client who connects late with the current state, keeps rooms as a Map of Sets so a message reaches only one group and cleans up when a client closes, and is tested with real ws clients on a port the test picks.

![Cheat sheet: Broadcasting and Rooms](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/018a49e92ef54aa7870dee74136d6be3.webp)

- Category: Node.js
- Level: Journeyman
- Tags: Broadcast, map() (javascript), node:test, nodejs, Set (javascript), Socket.IO, web-development, WebSocket Room
- Author: Gregor Dzierzon
- Updated: November 23, 2026

Source: https://www.ask-codey.com/cheat-sheets/node-websockets-broadcasting-cheat-sheet
