本文整理汇总了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
示例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
示例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
示例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