本文整理汇总了Python中connection.Connection.get_connection_ws方法的典型用法代码示例。如果您正苦于以下问题:Python Connection.get_connection_ws方法的具体用法?Python Connection.get_connection_ws怎么用?Python Connection.get_connection_ws使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类connection.Connection
的用法示例。
在下文中一共展示了Connection.get_connection_ws方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_message
# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import get_connection_ws [as 别名]
def on_message(self, message):
if not message:
return
# print(message)
if message == "request_code":
letters = [b for b in [random.choice(string.ascii_uppercase)
for a in range(5)]]
code = ""
for letter in letters:
code += letter
self.ws.send("code %s" % code)
elif message[:6] == "hello ":
command, session, role = message.split()
session = session.upper()
con = Connection.get_connection(session)
if role == "controller":
if con.connected("display"):
con.connect(role, self.ws)
con.display.send("controller_connected")
con.controller.send("connect_succesful")
else:
self.ws.send("connect_failed")
elif role == "display":
con.connect(role, self.ws)
else:
print("Error: unknown role: %s" % role)
else:
con = Connection.get_connection_ws(self.ws)
destination_ws = con.another_ws(self.ws)
if destination_ws is not None:
destination_ws.send(message)
示例2: on_close
# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import get_connection_ws [as 别名]
def on_close(self, reason):
con = Connection.get_connection_ws(self.ws)
if con.controller == self.ws and con.connected("display"):
con.display.send("controller_disconnected")
elif con.display == self.ws and con.connected("controller"):
con.controller.send("display_disconnected")
con.disconnect_ws(self.ws)