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


Python MQTTClient.reconnect方法代码示例

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


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

示例1: test_coro

# 需要导入模块: from hbmqtt.client import MQTTClient [as 别名]
# 或者: from hbmqtt.client.MQTTClient import reconnect [as 别名]
        def test_coro():
            try:
                broker = Broker(test_config, plugin_namespace="hbmqtt.test.plugins")
                yield from broker.start()
                self.assertTrue(broker.transitions.is_started())
                sub_client = MQTTClient()
                yield from sub_client.connect('mqtt://127.0.0.1', cleansession=False)
                ret = yield from sub_client.subscribe([('/qos0', QOS_0), ('/qos1', QOS_1), ('/qos2', QOS_2)])
                self.assertEqual(ret, [QOS_0, QOS_1, QOS_2])
                yield from sub_client.disconnect()
                yield from asyncio.sleep(0.1)

                yield from self._client_publish('/qos0', b'data', QOS_0, retain=True)
                yield from self._client_publish('/qos1', b'data', QOS_1, retain=True)
                yield from self._client_publish('/qos2', b'data', QOS_2, retain=True)
                yield from sub_client.reconnect()
                for qos in [QOS_0, QOS_1, QOS_2]:
                    log.debug("TEST QOS: %d" % qos)
                    message = yield from sub_client.deliver_message()
                    log.debug("Message: " + repr(message.publish_packet))
                    self.assertIsNotNone(message)
                    self.assertEqual(message.topic, '/qos%s' % qos)
                    self.assertEqual(message.data, b'data')
                    self.assertEqual(message.qos, qos)
                yield from sub_client.disconnect()
                yield from asyncio.sleep(0.1)
                yield from broker.shutdown()
                self.assertTrue(broker.transitions.is_stopped())
                future.set_result(True)
            except Exception as ae:
                future.set_exception(ae)
开发者ID:beerfactory,项目名称:hbmqtt,代码行数:33,代码来源:test_broker.py

示例2: test_coro

# 需要导入模块: from hbmqtt.client import MQTTClient [as 别名]
# 或者: from hbmqtt.client.MQTTClient import reconnect [as 别名]
        def test_coro():
            try:
                broker = Broker(broker_config, plugin_namespace="hbmqtt.test.plugins")
                yield from broker.start()
                client = MQTTClient()
                yield from client.connect('ws://fred:[email protected]:8080/')
                self.assertIsNotNone(client.session)
                yield from client.disconnect()
                yield from client.reconnect()

                self.assertIsNotNone(client.session.username)
                self.assertIsNotNone(client.session.password)
                yield from broker.shutdown()
                future.set_result(True)
            except Exception as ae:
                future.set_exception(ae)
开发者ID:beerfactory,项目名称:hbmqtt,代码行数:18,代码来源:test_client.py


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