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


Python MqttClient.clientid方法代码示例

本文整理汇总了Python中mqttcli.MqttClient.clientid方法的典型用法代码示例。如果您正苦于以下问题:Python MqttClient.clientid方法的具体用法?Python MqttClient.clientid怎么用?Python MqttClient.clientid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mqttcli.MqttClient的用法示例。


在下文中一共展示了MqttClient.clientid方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_003

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import clientid [as 别名]
    def test_003(self):
        monitor = MqttClient("monitor:{seq}", connect=4)
        # NOTE: '/' prefix skips $ messages
        # TODO: remove it when '$' filter will be impl.
        monitor.subscribe("/#", qos=0)

        client  = MqttClient("rabbit:{seq}", keepalive=2)
        will    = {'topic': '/node/disconnect', 'message': client.clientid()}
        client.connect(version=4, will=will)

        time.sleep(1)
        client.send_pingreq()
        evt = monitor.recv()
        if monitor.recv() != None:
            debug(evt)
            return False

        time.sleep(4)
        evt = monitor.recv()
        if not isinstance(evt, EventPublish) or evt.msg.topic != will['topic'] or \
                evt.msg.payload != will['message']:
            debug(evt)
            return False

        monitor.disconnect()
        return True
开发者ID:gbour,项目名称:wave,代码行数:28,代码来源:021_lastwill.py

示例2: test_002

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import clientid [as 别名]
    def test_002(self):
        monitor = MqttClient("monitor:{seq}", connect=4)
        # NOTE: '/' prefix skips $ messages
        # TODO: remove it when '$' filter will be impl.
        monitor.subscribe("/#", qos=0)

        client  = MqttClient("rabbit:{seq}")
        will    = {'topic': '/node/disconnect', 'message': client.clientid()}
        client.connect(version=4, will=will)
        # close socket without disconnection
        client.socket_close()

        evt = monitor.recv()
        if not isinstance(evt, EventPublish) or evt.msg.topic != will['topic'] or \
                evt.msg.payload != will['message']:
            debug(evt)
            return False

        monitor.disconnect()
        return True
开发者ID:gbour,项目名称:wave,代码行数:22,代码来源:021_lastwill.py

示例3: test_004

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import clientid [as 别名]
    def test_004(self):
        monitor = MqttClient("monitor:{seq}", connect=4)
        # NOTE: '/' prefix skips $ messages
        # TODO: remove it when '$' filter will be impl.
        monitor.subscribe("/#", qos=0)

        client  = MqttClient("rabbit:{seq}") # no keepalive
        will    = {'topic': '/node/disconnect', 'message': client.clientid()}
        client.connect(version=4, will=will)

        # protocol errlr flags shoud be 0
        client.forge(NC.CMD_PINGREQ, 4, [], send=True)
        if client.conn_is_alive():
            debug("connection still alive")
            return False

        evt = monitor.recv()
        if not isinstance(evt, EventPublish) or evt.msg.topic != will['topic'] or \
                evt.msg.payload != will['message']:
            debug(evt)
            return False

        monitor.disconnect()
        return True
开发者ID:gbour,项目名称:wave,代码行数:26,代码来源:021_lastwill.py

示例4: test_012

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import clientid [as 别名]
    def test_012(self):
        monitor = MqttClient("monitor:{seq}", connect=4)
        # NOTE: '/' prefix skips $ messages
        # TODO: remove it when '$' filter will be impl.
        monitor.subscribe("/#", qos=2)

        client  = MqttClient("rabbit:{seq}") # no keepalive
        will    = {'topic': '/node/disconnect', 'message': client.clientid(), 'retain': True}
        client.connect(version=4, will=will)
        client.socket_close()

        evt = monitor.recv()
        if not isinstance(evt, EventPublish) or evt.msg.topic != will['topic'] or \
                evt.msg.payload != will['message'] or \
                evt.msg.qos != 0:
            debug(evt)
            return False

        if not evt.msg.retain:
            debug("evt remain flag set")
            return False

        monitor.disconnect()
        return True
开发者ID:gbour,项目名称:wave,代码行数:26,代码来源:021_lastwill.py


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