本文整理汇总了Python中mqttcli.MqttClient类的典型用法代码示例。如果您正苦于以下问题:Python MqttClient类的具体用法?Python MqttClient怎么用?Python MqttClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MqttClient类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_102
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,代码行数:26,代码来源:020_v311.py
示例2: test_100
def test_100(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
e = c.subscribe("foo/bar", qos=0)
if e is not None:
debug(e)
return False
# socket MUST be disconnected
try:
e = c.publish("foo", "bar")
sock.getpeername()
except socket.error as e:
return True
debug("connection still alive")
return False
开发者ID:gbour,项目名称:wave,代码行数:27,代码来源:020_v311.py
示例3: test_007
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)
开发者ID:gbour,项目名称:wave,代码行数:27,代码来源:035_auth.py
示例4: test_008
def test_008(self):
client = MqttClient("rabbit:{seq}", raw_connect=True)
client.forge(NC.CMD_CONNECT, 0, [
('string', 'MQTT'),
('byte' , 4), # protocol level
('byte' , 28), # will=1, will-qos=3
('uint16', 60), # keepalive
], send=True)
if client.conn_is_alive():
debug("connection still alive")
return False
client = MqttClient("rabbit:{seq}", raw_connect=True)
client.forge(NC.CMD_CONNECT, 0, [
('string', 'MQTT'),
('byte' , 4), # protocol level
('byte' , 12), # will=1, will-qos=1
('uint16', 60), # keepalive
('string', client._c.client_id), # clientid
('string', '/foo/bar'),# will topic
('uint16', 0), # will payload len
('bytes' , ''), # will payload
], send=True)
evt = client.recv()
if not isinstance(evt, EventConnack):
debug(evt)
return False
client.disconnect()
return True
开发者ID:gbour,项目名称:wave,代码行数:31,代码来源:021_lastwill.py
示例5: test_011
def test_011(self):
c = MqttClient("reg:{seq}", connect=4)
e = c.publish("/foo/bar", "plop")
# QOS = 0 : no response indented
c.disconnect()
return (e is None)
开发者ID:gbour,项目名称:wave,代码行数:7,代码来源:001_basics.py
示例6: test_108
def test_108(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),
('byte' , 0), # flags
('uint16', 10), # keepalive
('string', '') # client id
], send=True)
evt = c._c.pop_event()
if not isinstance(evt, EventConnack) or evt.ret_code != 2:
debug(evt); return False
return True
开发者ID:gbour,项目名称:wave,代码行数:25,代码来源:020_v311.py
示例7: test_112
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
开发者ID:gbour,项目名称:wave,代码行数:26,代码来源:020_v311.py
示例8: test_109
def test_109(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
pkt = MqttPkt()
pkt.command = NC.CMD_CONNECT
pkt.remaining_length = 12 + 26 # client_id = "ff"
pkt.alloc()
pkt.write_string("MQTT")
pkt.write_byte(NC.PROTOCOL_VERSION_4)
pkt.write_byte(0) # flags
pkt.write_uint16(10) # keepalive
pkt.write_string("ABCDEFGHIJKLMNOPQRSTUVWXYZ") # client id - 26 chars
c._c.packet_queue(pkt)
c._c.packet_write()
c._c.loop()
if c.conn_is_alive():
debug("connection still alive")
return False
return True
开发者ID:gbour,项目名称:wave,代码行数:33,代码来源:020_v311.py
示例9: test_105
def test_105(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
ret = c.forge(NC.CMD_CONNECT, 0, [
('string', 'MQTT'),
('byte' , NC.PROTOCOL_VERSION_4),
('byte' , 1 << 6), # set password flag
('uint16', 60), # keepalive
('string', 'ff') # client id
], send=True)
if ret != NC.ERR_CONN_LOST:
debug("invalid error code: {0}".format(ret))
return False
return True
开发者ID:gbour,项目名称:wave,代码行数:25,代码来源:020_v311.py
示例10: test_103
def test_103(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_3),
('byte' , 0), # flags
('uint16', 60), # keepalive
('string', 'ff') # client id
], send=True) # should return CONN_REFUSED
evt = c._c.pop_event()
if not isinstance(evt, EventConnack) or evt.ret_code != 1:
debug(evt)
return False
ret = c._c.loop()
if ret != NC.ERR_CONN_LOST:
debug("invalid error code: {0}".format(ret))
return False
return True
开发者ID:gbour,项目名称:wave,代码行数:31,代码来源:020_v311.py
示例11: test_221
def test_221(self):
c = MqttClient("conformity:{seq}", connect=4)
ack = c.unsubscribe("foo/bar")
if not isinstance(ack, EventUnsuback):
debug(ack)
return False
return True
开发者ID:gbour,项目名称:wave,代码行数:8,代码来源:020_v311.py
示例12: test_010
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
开发者ID:gbour,项目名称:wave,代码行数:9,代码来源:032_websocket.py
示例13: test_223
def test_223(self):
c = MqttClient("conformity-sub:{seq}", connect=4)
c.disconnect()
if c.conn_is_alive():
debug("connection still alive")
return False
return True
开发者ID:gbour,项目名称:wave,代码行数:9,代码来源:020_v311.py
示例14: test_270
def test_270(self):
pub = MqttClient("luser:{seq}", connect=4)
pub.publish("$foo/bar", "test1")
if pub.conn_is_alive():
debug("connection still alive")
return False
return True
开发者ID:gbour,项目名称:wave,代码行数:9,代码来源:020_v311.py
示例15: test_010
def test_010(self):
c = MqttClient("v311:{seq}", connect=4)
evt = c.subscribe("/foo/bar", qos=0)
c.disconnect()
if not isinstance(evt, EventSuback):
debug(evt)
return False
return True
开发者ID:gbour,项目名称:wave,代码行数:10,代码来源:020_v311.py
示例16: test_001
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
开发者ID:gbour,项目名称:wave,代码行数:10,代码来源:020_v311.py
示例17: test_222
def test_222(self):
sub = MqttClient("conformity-sub:{seq}", connect=4)
ack = sub.unsubscribe_multi(["foo/bar", "bar/baz", "paper/+/scissor"])
if not isinstance(ack, EventUnsuback) or ack.mid != sub.get_last_mid():
debug(ack)
return False
sub.disconnect()
return True
开发者ID:gbour,项目名称:wave,代码行数:10,代码来源:020_v311.py
示例18: test_001
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
开发者ID:gbour,项目名称:wave,代码行数:10,代码来源:003_ssl.py
示例19: test_001
def test_001(self):
sub = MqttClient("sub:{seq}", connect=4)
suback_evt = sub.subscribe('foo/bar', qos=1)
if not isinstance(suback_evt, EventSuback) or \
suback_evt.mid != sub.get_last_mid() or \
suback_evt.granted_qos[0] != 1:
debug('failing event: {0}'.format(suback_evt))
return False
return True
开发者ID:gbour,项目名称:wave,代码行数:10,代码来源:006_qos1.py
示例20: test_002
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)
开发者ID:gbour,项目名称:wave,代码行数:10,代码来源:035_auth.py
注:本文中的mqttcli.MqttClient类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论