當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。