Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save crschmidt/03c4d8c8afd0d17b4d8a7749e8c09381 to your computer and use it in GitHub Desktop.
Save crschmidt/03c4d8c8afd0d17b4d8a7749e8c09381 to your computer and use it in GitHub Desktop.
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