Implement a Hub for Message Broadcasting
mainA Hub manages the lifecycle of clients and the distribution of messages.
Key Responsibilities:
- Registration: Adds client pointers to a
clientsmap. - Unregistration: Removes clients from the map and closes the client's
sendchannel to signal that no more messages will be sent. - Broadcasting: Iterates over registered clients and sends messages to their respective
sendchannels.
Error Handling: If a client's send buffer is full during a broadcast, the hub assumes the client is dead or stuck, unregisters them, and closes the WebSocket connection.