-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathhandlers.py
34 lines (25 loc) · 850 Bytes
/
handlers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
__author__ = 'Xsank'
import json
import tornado.web
import tornado.websocket
from util import object_to_json
from structure import InitData
from structure import CloseData
from structure import SyncPosition
class IndexHandler(tornado.web.RequestHandler):
def get(self):
self.render("Rumpetroll.htm",entry=None)
class WSHandler(tornado.websocket.WebSocketHandler):
clients=set()
@staticmethod
def broadcast(message):
for client in WSHandler.clients:
client.write_message(message)
def open(self):
WSHandler.clients.add(self)
self.write_message(object_to_json(InitData(id(self))))
def on_message(self, message):
WSHandler.broadcast(message)
def on_close(self):
WSHandler.clients.remove(self)
WSHandler.broadcast(object_to_json(CloseData(id(self))))