WebSocket hub

A WebSocket hub is a central component that manages active client connections and distributes messages to them. In this course, it maintains a subscribers map and gives each connected client an independent buffered send channel, allowing order-tracking updates to be distributed without performing network writes inside the hub.

Minimal example

go
type Hub struct {
    mu sync.Mutex
    subscribers map[*Client]bool
}

type Client struct {
    conn *websocket.Conn
    send chan []byte
}

Learn this concept

Lesson 5.2 · Managing WebSocket connections

Used in exercises

Exercise 5.3 · Per-user WebSocket hub Exercise 5.5 · Per-user order event bridge Exercise 5.11 · Order location stream Exercise 5.13 · Hub broadcast and claim race tests Exercise 5.16 · Topic subscription registry Exercise 8.11 · Two-minute project demo package