本文整理汇总了Python中mqttcli.MqttClient.forge方法的典型用法代码示例。如果您正苦于以下问题:Python MqttClient.forge方法的具体用法?Python MqttClient.forge怎么用?Python MqttClient.forge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mqttcli.MqttClient
的用法示例。
在下文中一共展示了MqttClient.forge方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_103
# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import forge [as 别名]
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
示例2: test_102
# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import forge [as 别名]
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
示例3: test_021
# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import forge [as 别名]
def test_021(self):
"""
throwing "anonymous" exception on binary pattern matching
(mqtt_msg:decode_connect2())
"""
client = MqttClient("rabbit:{seq}", raw_connect=True)
client.forge(NC.CMD_CONNECT, 0, [
('string', 'MQTT'),
('byte' , 4), # protocol level
('byte' , 4), # will=1
('uint16', 60), # keepalive
('string', client._c.client_id),
('string', '/will/topic'), # will-topic
], 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' , 4), # will=1
('uint16', 60), # keepalive
('string', client._c.client_id),
('string', '/will/topic'), # will-topic
('uint16', 4), # 4 bytes msg, BUT not message following
], send=True)
if client.conn_is_alive():
debug("connection still alive")
return False
return True
示例4: test_008
# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import forge [as 别名]
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
示例5: test_202
# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import forge [as 别名]
def test_202(self):
pub = MqttClient("conformity-pub:{seq}", connect=4)
sub = MqttClient("conformity-sub:{seq}", connect=4)
sub.subscribe("foo/bar", qos=2)
pub.publish("foo/bar", "wootwoot", qos=2, read_response=False)
# PUB PUBREC
evt = pub.recv()
# sending PUBREL with wrong pktid
pub.forge(NC.CMD_PUBREL, 2, [
('uint16', (evt.mid+10)%65535) # wrong pktid
], send=True)
# subscriber: PUBLISH never received
evt = sub.recv()
if evt is not None:
debug(evt)
return False
evt = pub.recv()
# publisher: PUBCOMP never received
if evt is not None:
debug(evt)
return False
pub.disconnect(); sub.disconnect()
return True
示例6: test_203
# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import forge [as 别名]
def test_203(self):
pub = MqttClient("conformity-pub:{seq}", connect=4)
sub = MqttClient("conformity-sub:{seq}", connect=4)
sub.subscribe("foo/bar", qos=2)
pub.publish("foo/bar", "wootwoot", qos=2, read_response=False)
# PUB PUBREC
evt = pub.recv()
pub.pubrel(pub.get_last_mid(), read_response=False)
# subscr: receiving PUBLISH
evt = sub.recv()
sub.pubrec(evt.msg.mid, read_response=False)
# subscr: receiving PUBREL
evt = sub.recv()
# sending PUBCOMP with wrong pktid
sub.forge(NC.CMD_PUBCOMP, 0, [
('uint16', (evt.mid+10)%65535) # wrong pktid
], send=True)
evt = pub.recv()
# publisher: PUBCOMP never received
if evt is not None:
debug(evt)
return False
pub.disconnect(); sub.disconnect()
return True
示例7: test_112
# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import forge [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
示例8: test_108
# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import forge [as 别名]
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
示例9: test_220
# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import forge [as 别名]
def test_220(self):
c = MqttClient("conformity:{seq}", connect=4)
c.forge(NC.CMD_UNSUBSCRIBE, 2, [
('uint16', 10), # identifier
# NOT TOPIC FILTER/QOS
], send=True)
if c.conn_is_alive():
debug("connection still alive")
return False
return True
示例10: test_215
# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import forge [as 别名]
def test_215(self):
c = MqttClient("conformity:{seq}", connect=4)
c.forge(NC.CMD_SUBSCRIBE, 2, [
('uint16', 42), # identifier
('string', '/foo/bar'), # topic filter
('byte' , 3) # qos
], send=True)
if c.conn_is_alive():
debug("connection still alive")
return False
return True
示例11: test_212
# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import forge [as 别名]
def test_212(self):
c = MqttClient("conformity:{seq}", connect=4)
# qos 1
c.forge(NC.CMD_PUBLISH, 2, [], send=True)
# ('uint16', 0), # identifier
# ], send=True)
if c.conn_is_alive():
debug("connection still alive")
return False
return True
示例12: test_211
# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import forge [as 别名]
def test_211(self):
c = MqttClient("conformity:{seq}", connect=4)
c.forge(NC.CMD_PUBLISH, 6, [
('string', '/foo/bar'), # topic
('uint16', 0), # identifier
], send=True)
if c.conn_is_alive():
debug("connection still alive")
return False
return True
示例13: test_210
# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import forge [as 别名]
def test_210(self):
c = MqttClient("conformity:{seq}", raw_connect=True)
c.forge(NC.CMD_CONNECT, 0, [
('string', 'MQTT'),
('byte' , 4), # protocol level
#('byte' , 128), # connect flags: username flag set
('byte' , 0), # no flags, no ClientId
('uint16', 60), # keepalive
], send=True)
return False
示例14: test_010
# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import forge [as 别名]
def test_010(self):
client = MqttClient("rabbit:{seq}", raw_connect=True)
client.forge(NC.CMD_CONNECT, 0, [
('string', 'MQTT'),
('byte' , 4), # protocol level
('byte' , 32), # will=0, will-retain=1
('uint16', 60), # keepalive
], send=True)
if client.conn_is_alive():
debug("connection still alive")
return False
return True
示例15: test_115
# 需要导入模块: from mqttcli import MqttClient [as 别名]
# 或者: from mqttcli.MqttClient import forge [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