ws_tornado_210.py
Go to the documentation of this file.
00001 # -*- coding: utf-8 -*-
00002 
00003 # pypi libraries
00004 import tornado.ioloop
00005 import tornado.web
00006 import tornado.websocket
00007 from tornado.ioloop import PeriodicCallback
00008 
00009 # local libraries
00010 import logging_util
00011 
00012 __all__ = [
00013     'ModWebSocketHandler',
00014 ]
00015 
00016 # create logger
00017 logger = logging_util.get_logger(__file__)
00018 
00019 
00020 class ModWebSocketProtocol8(tornado.websocket.WebSocketProtocol8):
00021     def _handle_message(self, opcode, data):
00022         if self.client_terminated:
00023             return
00024 
00025         if opcode == 0xA:
00026             self.async_callback(self.handler.on_pong)(data)
00027 
00028         super(ModWebSocketProtocol8, self)._handle_message(opcode, data)
00029 
00030 
00031 class ModWebSocketHandler(tornado.websocket.WebSocketHandler):
00032     """
00033     """
00034     def write_message(self, message, binary=False):
00035         self.ws_connection.write_message(message, binary)
00036 
00037     def _execute(self, transform, *args, **kwargs):
00038         try:
00039             self.open_args = args
00040             self.open_kwargs = kwargs
00041 
00042             version = self.request.headers.get('Sec-WebSocket-Version')
00043             if version in ('8', '7', '13'):
00044                 self.ws_connection = ModWebSocketProtocol8(self)
00045                 self.ws_connection.accept_connection()
00046 
00047             elif version:
00048                 self.stream.write(tornado.escape.utf8(
00049                     "HTTP/1.1 426 Upgrade Required\r\n"
00050                     "Sec-WebSocket-Version: 8\r\n\r\n"))
00051                 self.stream.close()
00052 
00053             else:
00054                 self.ws_connection = tornado.websocket.WebSocketProtocol76(self)
00055                 self.ws_connection.accept_connection()
00056 
00057         except Exception as err:
00058             logger.err(err)
00059 
00060     def ping(self, data):
00061         if not self.ws_connection.client_terminated:
00062             self.ws_connection._write_frame(True, 0x9, data)


rospeex_webaudiomonitor
Author(s): Komei Sugiura
autogenerated on Thu Jun 6 2019 18:53:16