我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用tornado.websocket.WebSocketHandler()。
def on_close(self): """Overwrites WebSocketHandler.close. Close Game, send message to Paired client that game has ended """ self.send_pair_message(action="end", game_id=self.game_id, result="A") self.game_manager.end_game(self.game_id)
def __init__(self, app, request, clients, **kwargs): websocket.WebSocketHandler.__init__(self, app, request, **kwargs) self.clients = clients self.client = None
def __init__(self): super(WebSocketConnectionHandler, self).__init__( factory=WebSocketHandler)
def __init__(self, *args, **kwargs): websocket.WebSocketHandler.__init__(self, *args, **kwargs) if WebSocket._zmq_stream is None: raise RuntimeError("Please install a stream before instantiating " "any websockets") self.authenticated = False self.auth_failures = 0 self.max_auth_fails = 3 self.username = None
def test_add_handler_with_tornado_app_instance(self): self.assertIsNone(TornadoWrapper.app) self.assertListEqual(TornadoWrapper.handlers, []) TornadoWrapper.start_app() self.assertIsNotNone(TornadoWrapper.app) with self.assertRaisesRegexp(AttributeError, "'str' object has no attribute 'name'"): TornadoWrapper.add_handler('a string') TornadoWrapper.add_handler([('path', WebSocketHandler, {})]) TornadoWrapper.add_handler(('path2', WebSocketHandler, {}))