title: How to broadcast message to all active clients in tornado.websockets?
body: <p>In <a href="https://github.com/tornadoweb/tornado" rel="nofollow noreferrer">Tornado</a> implementation of <a href="https://www.rfc-editor.org/rfc/rfc6455" rel="nofollow noreferrer">Websocket</a> one needs to use <a href="https://github.com/tornadoweb/tornado/blob/master/tornado/websocket.py#L60" rel="nofollow noreferrer">WebSocketHandler</a> a subclass of a RequestHandler for handling communication with websocket clients. Example in the <a href="http://www.tornadoweb.org/en/stable/websocket.html" rel="nofollow noreferrer">docs</a> demonstrate how to write a message back to the client in a response to their message, but the documentation does not make it clear what is the right way to implement broadcasting to the clients which did not participate in the exchange (for instance to all active clients).</p>
  <p>How should one go about broadcasting a message to all actively connected websocket clients in tornado.websocket? I posted my current approach as one of the answers.</p>
  <p>Solution I am using now was mentioned in a <a href="https://stackoverflow.com/questions/27757506/broadcasting-a-message-using-tornado">slightly related question</a> and also used in one chat example. I would like to learn however if there is a better way, or if this one is indeed how it should be done.</p>
  <p>EDIT1: Another related question using the same approach: <a href="https://stackoverflow.com/questions/27757506/broadcasting-a-message-using-tornado">Broadcasting a message using Tornado</a></p>