forked from py499372727/AgentSims
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
41 lines (31 loc) · 1.02 KB
/
main.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
import tornado.ioloop
# import tornado.web
import tornado.websocket
# import subprocess
from app import App
class WebSocketHandler(tornado.websocket.WebSocketHandler):
app_cache = App()
ping_interval = 0
def check_origin(self,remote_address):
# CORS
return True
def open(self):
self.app_cache.register(self)
def on_close(self):
# print("connection closing")
self.app_cache.logout(self)
async def on_message(self, message):
await self.app_cache.execute(self, message)
class Application(tornado.web.Application):
def __init__(self):
handlers = [
(r'/ws', WebSocketHandler),
]
tornado.web.Application.__init__(self, handlers, websocket_ping_interval=0)
if __name__ == "__main__":
print("----------Server Started----------")
app = Application()
app.listen(8000, address='0.0.0.0')
# subprocess.call("python3 -u tick.py")
tornado.ioloop.IOLoop.current().start()
print("----------Server Stopped----------")