当前位置: 首页>>代码示例>>Python>>正文


Python Connection.get_connection_ws方法代码示例

本文整理汇总了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)
开发者ID:poletaevvlad,项目名称:WS-experement,代码行数:37,代码来源:ws_server.py

示例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)
开发者ID:poletaevvlad,项目名称:WS-experement,代码行数:11,代码来源:ws_server.py


注:本文中的connection.Connection.get_connection_ws方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。