Skip to content

Instantly share code, notes, and snippets.

@aluminiumgeek
Last active January 4, 2016 02:39
Show Gist options
  • Save aluminiumgeek/8556607 to your computer and use it in GitHub Desktop.
Save aluminiumgeek/8556607 to your computer and use it in GitHub Desktop.
Tornado Websocket example for blog
class UpdatesHandler(websocket.WebSocketHandler):
socket_clients = set()
def open(self):
self.socket_clients.add(self)
def on_close(self):
self.socket_clients.remove(self)
@classmethod
def send_updates(cls, data):
for client in cls.socket_clients:
client.write_message(data)
# Использовать можно из любого места
data = {
'type': 'new_message',
'data': 'Hello!'
}
UpdatesHandler.send_updates(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment