Created
April 1, 2015 13:58
-
-
Save arbarlow/c24bf2d4b1a8fc93c7df 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
class WebSocketHandler(tornado.websocket.WebSocketHandler): | |
_PING_INTERVAL = 3.0 | |
_DISCONNECT_TIMEOUT = 10.0 | |
connections = set() | |
button = Button() | |
def open(self): | |
self.id = self.get_argument("id") | |
WebSocketHandler.connections.add(self) | |
self._add_periodic_ping() | |
self._add_cleanup_timeout() | |
WebSocketHandler.broadcast_connections(self) | |
def _add_periodic_ping(self): | |
self._periodic_ping = tornado.ioloop.PeriodicCallback( | |
functools.partial(self.ping, "0"), self._PING_INTERVAL * 1000.0) | |
self._periodic_ping.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment