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


Python MqttClient.send_pingreq方法代码示例

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


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

示例1: test_003

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import send_pingreq [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_102

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import send_pingreq [as 别名]
    def test_102(self):
        c = MqttClient("conformity:{seq}")
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        try:
            sock.connect(('127.0.0.1', 1883))
            sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
            sock.setblocking(0)
        except Exception as e:
            debug(e)
            return False

        c._c.sock = sock
        c.forge(NC.CMD_CONNECT, 0, [
            ('string', 'MqTt'),
            ('byte'  , NC.PROTOCOL_VERSION_4),
            ('string', 'ff') # client id
        ], send=True)

        try:
            c.send_pingreq()
            c._c.sock.getpeername()
        except socket.error as e:
            return True

        debug("connection still alive")
        return False
开发者ID:gbour,项目名称:wave,代码行数:28,代码来源:020_v311.py

示例3: test_020

# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import send_pingreq [as 别名]
    def test_020(self):
        c = MqttClient("reg:{seq}", connect=4)
        e = c.send_pingreq()
        c.disconnect()

        return isinstance(e, EventPingResp)
开发者ID:gbour,项目名称:wave,代码行数:8,代码来源:001_basics.py


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