Created
May 28, 2017 01:11
-
-
Save crschmidt/03c4d8c8afd0d17b4d8a7749e8c09381 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tornado import websocket, web, ioloop | |
import json | |
clients = [] | |
class SocketHandler(websocket.WebSocketHandler): | |
def check_origin(self, origin): | |
return True | |
def open(self, key=None): | |
self.key = key | |
if self not in clients: | |
clients.append(self) | |
def on_close(self): | |
if self in cl: | |
clients.remove(self) | |
class ApiHandler(web.RequestHandler): | |
@web.asynchronous | |
def get(self, *args): | |
self.finish() | |
key = self.get_argument("key") | |
for c in clients: | |
if c.key == key: | |
c.write_message("now") | |
@web.asynchronous | |
def post(self): | |
pass | |
app = web.Application([ | |
(r'/ws/([A-Za-z0-9]*)', SocketHandler), | |
(r'/api', ApiHandler), | |
]) | |
if __name__ == '__main__': | |
app.listen(8888) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment