Broadcasting Messages
Send to many clients.
Sending to Many Clients
Chat rooms and live feeds need to push a single message to every connected client. Since each WebSocket allows only one writer, you need a coordination pattern: the hub.
The Hub Pattern
A hub is a central goroutine that owns the set of clients and a broadcast channel. Clients register, unregister, and the hub fans messages out. No shared map is touched by multiple goroutines directly.
All lessons in this course
- WebSocket Basics
- Using gorilla/websocket
- Broadcasting Messages
- Connection Management