本文整理汇总了Python中tornado.websocket.WebSocketHandler方法的典型用法代码示例。如果您正苦于以下问题:Python websocket.WebSocketHandler方法的具体用法?Python websocket.WebSocketHandler怎么用?Python websocket.WebSocketHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tornado.websocket
的用法示例。
在下文中一共展示了websocket.WebSocketHandler方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from tornado import websocket [as 别名]
# 或者: from tornado.websocket import WebSocketHandler [as 别名]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# since my parent doesn't keep calling the super() constructor,
# I need to do it myself
bases = inspect.getmro(type(self))
assert WebSocketHandlerMixin in bases
meindex = bases.index(WebSocketHandlerMixin)
try:
nextparent = bases[meindex + 1]
except IndexError:
raise Exception("WebSocketHandlerMixin should be followed "
"by another parent to make sense")
# undisallow methods --- t.ws.WebSocketHandler disallows methods,
# we need to re-enable these methods
def wrapper(method):
def undisallow(*args2, **kwargs2):
getattr(nextparent, method)(self, *args2, **kwargs2)
return undisallow
for method in ["write", "redirect", "set_header", "set_cookie",
"set_status", "flush", "finish"]:
setattr(self, method, wrapper(method))
nextparent.__init__(self, *args, **kwargs)
示例2: write_message
# 需要导入模块: from tornado import websocket [as 别名]
# 或者: from tornado.websocket import WebSocketHandler [as 别名]
def write_message(self, message, binary=False):
super(WebSocketHandler, self).write_message(message, binary)
示例3: __init__
# 需要导入模块: from tornado import websocket [as 别名]
# 或者: from tornado.websocket import WebSocketHandler [as 别名]
def __init__(self, *args, **kwargs):
super(WebSocketHandler, self).__init__(*args, **kwargs)
self._init_handler()
示例4: check_origin
# 需要导入模块: from tornado import websocket [as 别名]
# 或者: from tornado.websocket import WebSocketHandler [as 别名]
def check_origin(self, origin):
"""
Overridden function from WebSocketHandler for CORS policy.
This ensures that websocket connection can be made from any
origin.
"""
return True
示例5: open
# 需要导入模块: from tornado import websocket [as 别名]
# 或者: from tornado.websocket import WebSocketHandler [as 别名]
def open(self):
"""
A new websocket connection is opened.
Overridden function from WebSocketHandler
This method resets the global connection variables.
"""
self.__reset_connection()
示例6: on_message
# 需要导入模块: from tornado import websocket [as 别名]
# 或者: from tornado.websocket import WebSocketHandler [as 别名]
def on_message(self, message):
"""
Got a messege from the websocket connection.
Overridden method from WebSocketHandler.
This method recieves the message from the websocket connection and
validates the message. If the message is validated it extracts the
data from the message and pass it as an argument to the function
registered corresponding to the users socket-id. The returned value
from the function is sent back to user as a response.
Args:
message: message from the websocket connection. \
This message is what we got from the websocket, first we need \
to validate it and then extract the required matter from it \
which will then be used by the registered function.
"""
data = self._validate_message(message)
if data:
out_msg = self.active_connection["func"](
*self.active_connection["arguments"], message=data)
try:
# Send the out_msg returned from the function.
if isinstance(out_msg, dict):
json_resp = json.dumps(out_msg)
self.write_message(json_resp)
elif utils.check_if_string(out_msg):
self.write_message(out_msg)
# self._origmai_send_data(
# "ws_data", out_msg, socketId=self.connection_id)
else:
print(
"A persistent connection can only return a python dict \
or string")
except Exception:
pass
示例7: __init__
# 需要导入模块: from tornado import websocket [as 别名]
# 或者: from tornado.websocket import WebSocketHandler [as 别名]
def __init__(self, *args, **kwargs):
websocket.WebSocketHandler.__init__(self, *args, **kwargs)
handlers.IPythonHandler.__init__(self, *args, **kwargs)
ca_certs = None
if self.request.protocol == 'https':
ca_certs = self.config.get('NotebookApp', {}).get('certfile')
if not ca_certs:
raise ValueError('HTTPS requires the NotebookApp.certfile setting to '
'be present.')
self.ca_certs = ca_certs
示例8: __init__
# 需要导入模块: from tornado import websocket [as 别名]
# 或者: from tornado.websocket import WebSocketHandler [as 别名]
def __init__(self, application, request, **kwargs):
super(WebSocketHandler, self).__init__(application, request, **kwargs)
self.remote_ip = request.headers.get(
'X-Forwarded-For',
request.headers.get(
'X-Real-Ip',
request.remote_ip))
application.log('INFO', 'CONNECTION_OPEN', self.remote_ip )
self.trade_client = None
self.user_response = None
self.last_message_datetime = [datetime.now()]
self.open_orders = {}
self.md_subscriptions = {}
self.sec_status_subscriptions = {}
self.honey_pot_connection = False
if self.application.is_tor_node( self.remote_ip ):
self.honey_pot_connection = True
application.log('INFO', 'BLOCKED_TOR_NODE', self.remote_ip )
return
self.trade_client = TradeClient(
self.application.zmq_context,
self.application.trade_in_socket,
self.application.options.trade_pub)
示例9: close
# 需要导入模块: from tornado import websocket [as 别名]
# 或者: from tornado.websocket import WebSocketHandler [as 别名]
def close(self, code=None, reason=None):
self.application.log('DEBUG', self.remote_ip, 'WebSocketHandler.close() invoked' )
super(WebSocketHandler, self).close()