本文整理汇总了Python中mqttcli.MqttClient.connect方法的典型用法代码示例。如果您正苦于以下问题:Python MqttClient.connect方法的具体用法?Python MqttClient.connect怎么用?Python MqttClient.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mqttcli.MqttClient
的用法示例。
在下文中一共展示了MqttClient.connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_003
# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import connect [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_112
# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import connect [as 别名]
def test_112(self):
## PINGREG
c = MqttClient("conformity:{seq}", raw_connect=True)
evt = c.connect(version=4)
# flags shoud be 0
c.forge(NC.CMD_PINGREQ, 4, [], send=True)
if c.conn_is_alive():
debug("connection still alive")
return False
## SUBSCRIBE
c = MqttClient("conformity2:{seq}", raw_connect=True)
evt = c.connect(version=4)
# flags shoud be 2
c.forge(NC.CMD_SUBSCRIBE, 3, [
('uint16', 42), # identifier
('string', '/foo/bar'), # topic filter
('byte' , 0) # qos
], send=True)
if c.conn_is_alive():
debug("connection still alive")
return False
return True
示例3: test_007
# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import connect [as 别名]
def test_007(self):
tmp = tempfile.mktemp(prefix='wave-testsuite-')
subprocess.Popen("echo \"bar\"|../bin/mkpasswd -c {0} foo".format(tmp),
shell=True, stdout=subprocess.PIPE).wait()
yield app.set_auth(required= True, filename= tmp)
yield auth.switch(tmp)
c = MqttClient("auth:{seq}", connect=False, username="foo", password="baz")
ret = c.connect(version=4)
# auth rejected
if not isinstance(ret, EventConnack) or ret.ret_code == 0:
debug(ret)
defer.returnValue(False)
# updating password
subprocess.Popen("echo \"baz\"|../bin/mkpasswd {0} foo".format(tmp),
shell=True, stdout=subprocess.PIPE).wait()
# file is monitored each 2 secs in debug context
time.sleep(3)
ret = c.connect(version=4)
# auth accepted
if not isinstance(ret, EventConnack) or ret.ret_code != 0:
debug(ret)
defer.returnValue(False)
defer.returnValue(True)
示例4: test_010
# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import connect [as 别名]
def test_010(self):
cli = MqttClient("ws:{seq}", port=8884, websocket=True, ssl=True, ssl_opts={'ssl_version': SSL_VERSION})
evt = cli.connect(version=4)
if not isinstance(evt, EventConnack):
debug(evt)
return False
cli.disconnect()
return True
示例5: test_001
# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import connect [as 别名]
def test_001(self):
c = MqttClient("v311:{seq}")
evt = c.connect(version=4)
if not isinstance(evt, EventConnack) or \
evt.ret_code:
debug(evt)
return False
return True
示例6: test_001
# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import connect [as 别名]
def test_001(self):
c = MqttClient("reg:{seq}", ssl=True, ssl_opts={'ssl_version': SSL_VERSION})
evt = c.connect()
debug("Using SSL: version={0}, cipher={1}".format(version(c._c.sock), c._c.sock.cipher()))
if not isinstance(evt, EventConnack):
return False
c.disconnect()
return True
示例7: test_002
# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import connect [as 别名]
def test_002(self):
yield app.set_auth(required=True)
c = MqttClient("auth:{seq}", connect=False)
ret = c.connect(version=4)
if isinstance(ret, EventConnack) and ret.ret_code == 4:
defer.returnValue(True)
debug(ret)
defer.returnValue(False)
示例8: test_003
# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import connect [as 别名]
def test_003(self):
tmp = tempfile.mktemp(prefix='wave-testsuite-')
yield app.set_auth(required=True, filename=tmp); yield auth.switch(tmp)
c = MqttClient("auth:{seq}", connect=False)
ret = c.connect(version=4)
if isinstance(ret, EventConnack) and ret.ret_code == 4:
defer.returnValue(True)
debug(ret)
defer.returnValue(False)
示例9: test_002
# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import connect [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
示例10: test_008
# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import connect [as 别名]
def test_008(self):
tmp = tempfile.mktemp(prefix='wave-testsuite-')
debug("pwd file: {0}".format(tmp))
proc = subprocess.Popen("echo \"bar\"|../bin/mkpasswd -c {0} foo".format(tmp),
shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(out,err) = proc.communicate()
debug("out: {0}".format(out)); debug("err: {0}".format(err))
with open(tmp, 'r') as f:
debug(f.read())
yield app.set_auth(required= True, filename= tmp)
yield auth.switch(tmp)
c = MqttClient("auth:{seq}", connect=False, username="foo", password="bar")
ret = c.connect(version=4)
# auth rejected
if not isinstance(ret, EventConnack) or ret.ret_code != 0:
debug(ret)
defer.returnValue(False)
c.disconnect()
# deleting password
proc = subprocess.Popen("../bin/mkpasswd -D {0} foo && touch {0}".format(tmp),
shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(out,err) = proc.communicate()
debug("out: {0}".format(out)); debug("err: {0}".format(err))
with open(tmp, 'r') as f:
debug(f.read())
# file is monitored each 2 secs in debug context
#time.sleep(5)
yield auth.switch(tmp)
ret = c.connect(version=4)
# auth accepted
if not isinstance(ret, EventConnack) or ret.ret_code != 4:
debug(ret)
defer.returnValue(False)
defer.returnValue(True)
示例11: test_002
# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import connect [as 别名]
def test_002(self):
c = MqttClient("reg:{seq}", ssl=True, ssl_opts={
'ssl_version': SSL_VERSION,
'cert_reqs': ssl.CERT_REQUIRED
})
evt = c.connect()
if not isinstance(evt, EventConnack):
return True
c.disconnect()
return False
示例12: test_001
# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import connect [as 别名]
def test_001(self):
c = MqttClient("reg:{seq}")
evt = c.connect()
# [MQTT-3.1.4-4]: CONNACK retcode MUST be 0
# [MQTT-3.2.2-3]: CONNACK session_present IS 0
if not isinstance(evt, EventConnack) or \
evt.ret_code != 0 or \
evt.session_present != 0:
return False
return True
示例13: test_003
# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import connect [as 别名]
def test_003(self):
c = MqttClient("reg:{seq}", ssl=True, ssl_opts={
'ssl_version': SSL_VERSION,
'cert_reqs': ssl.CERT_REQUIRED,
'ca_certs': os.path.join(os.path.dirname(__file__), "../../", "etc/wave_cert.pem")
})
evt = c.connect()
if not isinstance(evt, EventConnack):
return False
c.disconnect()
return True
示例14: test_001
# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import connect [as 别名]
def test_001(self):
from nyamuk import nyamuk_ws
subproto= nyamuk_ws.SUBPROTOCOLS[4]; nyamuk_ws.SUBPROTOCOLS[4] = 'foobar'
cli = MqttClient("ws:{seq}", port=1884, websocket=True)
status = cli.connect(version=4)
nyamuk_ws.SUBPROTOCOLS[4] = subproto
if status != NC.ERR_SUCCESS:
debug(status)
return True
return False
示例15: test_115
# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import connect [as 别名]
def test_115(self):
c = MqttClient("conformity:{seq}", raw_connect=True)
evt = c.connect(version=4)
c.forge(NC.CMD_UNSUBSCRIBE, 2, [
('uint16', 0), # identifier
('string', '/foo/bar'), # topic filter
], send=True)
if c.conn_is_alive():
debug("connection still alive")
return False
return True