-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsio-test.py
59 lines (40 loc) · 1.38 KB
/
sio-test.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import tornado.ioloop
import tornado.web
from tornado.web import HTTPError, RequestHandler, Application
from tornadio2 import SocketConnection, TornadioRouter, SocketServer, event
class BackboneConnection(SocketConnection):
@event
def sync(self, url, method, model, options):
print(method, url, model, options)
self.emit(model)
def on_create(self, model, options):
raise NotImplementedError
def on_read(self, model, options):
raise NotImplementedError
def on_update(self, model, options):
raise NotImplementedError
def on_delete(self, model, options):
raise NotImplementedError
class IndexHandler(RequestHandler):
def get(self):
self.render("static/test.html")
class SocketIOHandler(RequestHandler):
def get(self):
self.render("static/socket.io.js")
SyncRouter = TornadioRouter(BackboneConnection)
sio_application = Application(
SyncRouter.apply_routes([
(r"/socket.io.js", SocketIOHandler)
]),
socket_io_port = 8001
)
web_application = Application([
(r"/", IndexHandler),
(r"/(.*)", tornado.web.StaticFileHandler, {"path": "static"})
])
if __name__ == "__main__":
import logging
logging.getLogger().setLevel(logging.DEBUG)
SocketServer(sio_application, auto_start=False)
web_application.listen(8888)
tornado.ioloop.IOLoop.instance().start()