我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用tornado.websocket.html()。
def emit(self, event, data): """ Sends a given event/data combinaison to the client of this WebSocket. Wrapper for `tornado.websocket.WebSocketHandler.write_message <http://www.tornadoweb.org/en/stable/ websocket.html#tornado.websocket.WebSocketHandler.write_message>`_ method. :param event: event name to emit :param data: associated data :type event: str :type data: dict """ self.write_message({ 'event': event, 'data': data })
def on_close(self): if self.group in listeners: listeners[self.group].remove(self) del names[self] # notify clients that a member has left the groups for client in listeners.get(self.group, []): client.write_message('-' + self.name) print('%s:DISCONNECT from %s' % (time.time(), self.group)) # if your webserver is different from tornado server uncomment this # or override using something more restrictive: # http://tornado.readthedocs.org/en/latest/websocket.html#tornado.websocket.WebSocketHandler.check_origin # def check_origin(self, origin): # return True
def check_origin(self, origin): """ Accepts all cross-origin traffic :param origin: is the value of the ``Origin`` HTTP header, the url responsible for initiating this request. .. seealso:: `~WebSocketHandler.check_origin <http://www.tornadoweb.org/en/stable/_modules/tornado/websocket.html#WebSocketHandler.check_origin>` """ return True
def on_close(self): if self.group in listeners: listeners[self.group].remove(self) del names[self] # notify clients that a member has left the groups for client in listeners.get(self.group, []): client.write_message('-' + self.name) print '%s:DISCONNECT from %s' % (time.time(), self.group) # if your webserver is different from tornado server uncomment this # or override using something more restrictive: # http://tornado.readthedocs.org/en/latest/websocket.html#tornado.websocket.WebSocketHandler.check_origin # def check_origin(self, origin): # return True