本文整理汇总了Python中mosq_test.gen_connack函数的典型用法代码示例。如果您正苦于以下问题:Python gen_connack函数的具体用法?Python gen_connack怎么用?Python gen_connack使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了gen_connack函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pattern_test
def pattern_test(sub_topic, pub_topic):
rc = 1
keepalive = 60
connect_packet = mosq_test.gen_connect("pattern-sub-test", keepalive=keepalive)
connack_packet = mosq_test.gen_connack(rc=0)
publish_packet = mosq_test.gen_publish(pub_topic, qos=0, payload="message")
publish_retained_packet = mosq_test.gen_publish(pub_topic, qos=0, retain=True, payload="message")
mid = 312
subscribe_packet = mosq_test.gen_subscribe(mid, sub_topic, 0)
suback_packet = mosq_test.gen_suback(mid, 0)
mid = 234;
unsubscribe_packet = mosq_test.gen_unsubscribe(mid, sub_topic)
unsuback_packet = mosq_test.gen_unsuback(mid)
broker = subprocess.Popen(['../../src/mosquitto', '-p', '1888'], stderr=subprocess.PIPE)
try:
time.sleep(0.5)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(("localhost", 1888))
sock.settimeout(20)
sock.send(connect_packet)
if mosq_test.expect_packet(sock, "connack", connack_packet):
sock.send(subscribe_packet)
if mosq_test.expect_packet(sock, "suback", suback_packet):
pub = subprocess.Popen(['./03-pattern-matching-helper.py', pub_topic])
pub.wait()
if mosq_test.expect_packet(sock, "publish", publish_packet):
sock.send(unsubscribe_packet)
if mosq_test.expect_packet(sock, "unsuback", unsuback_packet):
sock.send(subscribe_packet)
if mosq_test.expect_packet(sock, "suback", suback_packet):
if mosq_test.expect_packet(sock, "publish retained", publish_retained_packet):
rc = 0
sock.close()
finally:
broker.terminate()
broker.wait()
if rc:
(stdo, stde) = broker.communicate()
print(stde)
return rc
示例2: pattern_test
def pattern_test(sub_topic, pub_topic):
rc = 1
keepalive = 60
connect_packet = mosq_test.gen_connect("pattern-sub-test", keepalive=keepalive)
connack_packet = mosq_test.gen_connack(rc=0)
publish_packet = mosq_test.gen_publish(pub_topic, qos=0, payload="message")
publish_retained_packet = mosq_test.gen_publish(pub_topic, qos=0, retain=True, payload="message")
mid = 312
subscribe_packet = mosq_test.gen_subscribe(mid, sub_topic, 0)
suback_packet = mosq_test.gen_suback(mid, 0)
mid = 234;
unsubscribe_packet = mosq_test.gen_unsubscribe(mid, sub_topic)
unsuback_packet = mosq_test.gen_unsuback(mid)
port = mosq_test.get_port()
broker = subprocess.Popen(['../../src/mosquitto', '-p', str(port)], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
try:
time.sleep(0.5)
sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=20, port=port)
sock.send(subscribe_packet)
if mosq_test.expect_packet(sock, "suback", suback_packet):
pub = subprocess.Popen(['./03-pattern-matching-helper.py', pub_topic, str(port)], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
pub.wait()
(stdo, stde) = pub.communicate()
if mosq_test.expect_packet(sock, "publish", publish_packet):
sock.send(unsubscribe_packet)
if mosq_test.expect_packet(sock, "unsuback", unsuback_packet):
sock.send(subscribe_packet)
if mosq_test.expect_packet(sock, "suback", suback_packet):
if mosq_test.expect_packet(sock, "publish retained", publish_retained_packet):
rc = 0
sock.close()
finally:
broker.terminate()
broker.wait()
(stdo, stde) = broker.communicate()
if rc:
print(stde)
print(stdo)
raise
return rc
示例3: print
if sys.version < '2.7':
print("WARNING: SSL not supported on Python 2.6")
exit(0)
import inspect, os, sys
# From http://stackoverflow.com/questions/279237/python-import-a-module-from-a-folder
cmd_subfolder = os.path.realpath(os.path.abspath(os.path.join(os.path.split(inspect.getfile( inspect.currentframe() ))[0],"..")))
if cmd_subfolder not in sys.path:
sys.path.insert(0, cmd_subfolder)
import mosq_test
rc = 1
keepalive = 10
connect_packet = mosq_test.gen_connect("connect-cert-test", keepalive=keepalive)
connack_packet = mosq_test.gen_connack(rc=0)
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=1889)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ssock = ssl.wrap_socket(sock, ca_certs="../ssl/test-root-ca.crt", cert_reqs=ssl.CERT_REQUIRED)
ssock.settimeout(20)
try:
ssock.connect(("localhost", 1888))
except ssl.SSLError as err:
if err.errno == 1:
rc = 0
except socket.error as err:
if err.errno == errno.ECONNRESET:
rc = 0
示例4:
import inspect, os, sys
# From http://stackoverflow.com/questions/279237/python-import-a-module-from-a-folder
cmd_subfolder = os.path.realpath(os.path.abspath(os.path.join(os.path.split(inspect.getfile( inspect.currentframe() ))[0],"..")))
if cmd_subfolder not in sys.path:
sys.path.insert(0, cmd_subfolder)
import mosq_test
port = mosq_test.get_port()
rc = 1
mid = 3265
keepalive = 60
connect_packet = mosq_test.gen_connect("pub-qos1-disco-test", keepalive=keepalive, clean_session=False)
connack1_packet = mosq_test.gen_connack(resv=0, rc=0)
connack2_packet = mosq_test.gen_connack(resv=1, rc=0)
subscribe_packet = mosq_test.gen_subscribe(mid, "qos1/disconnect/test", 1)
suback_packet = mosq_test.gen_suback(mid, 1)
mid = 1
publish_packet = mosq_test.gen_publish("qos1/disconnect/test", qos=1, mid=mid, payload="disconnect-message")
publish_dup_packet = mosq_test.gen_publish("qos1/disconnect/test", qos=1, mid=mid, payload="disconnect-message", dup=True)
puback_packet = mosq_test.gen_puback(mid)
mid = 3266
publish2_packet = mosq_test.gen_publish("qos1/outgoing", qos=1, mid=mid, payload="outgoing-message")
puback2_packet = mosq_test.gen_puback(mid)
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
示例5:
# Test what the broker does if receiving a PUBREC in response to a QoS 1 PUBLISH.
import inspect, os, sys
# From http://stackoverflow.com/questions/279237/python-import-a-module-from-a-folder
cmd_subfolder = os.path.realpath(os.path.abspath(os.path.join(os.path.split(inspect.getfile( inspect.currentframe() ))[0],"..")))
if cmd_subfolder not in sys.path:
sys.path.insert(0, cmd_subfolder)
import mosq_test
import time
rc = 1
keepalive = 60
connect_packet = mosq_test.gen_connect("subpub-qos1-test", keepalive=keepalive)
connack_packet = mosq_test.gen_connack(rc=0)
mid = 1
subscribe_packet = mosq_test.gen_subscribe(mid, "subpub/qos1", 1)
suback_packet = mosq_test.gen_suback(mid, 1)
helper_connect = mosq_test.gen_connect("helper", keepalive=keepalive)
helper_connack = mosq_test.gen_connack(rc=0)
mid = 1
publish1s_packet = mosq_test.gen_publish("subpub/qos1", qos=1, mid=mid, payload="message")
puback1s_packet = mosq_test.gen_puback(mid)
mid = 1
publish1r_packet = mosq_test.gen_publish("subpub/qos1", qos=1, mid=mid, payload="message")
pubrec1r_packet = mosq_test.gen_pubrec(mid)
示例6:
# sub does not receive the message
import inspect, os, sys
# From http://stackoverflow.com/questions/279237/python-import-a-module-from-a-folder
cmd_subfolder = os.path.realpath(os.path.abspath(os.path.join(os.path.split(inspect.getfile( inspect.currentframe() ))[0],"..")))
if cmd_subfolder not in sys.path:
sys.path.insert(0, cmd_subfolder)
import mosq_test
rc = 1
keepalive = 60
connect_packet_sub_persistent = mosq_test.gen_connect("flipflop-test", keepalive=keepalive, clean_session=False)
connect_packet_sub_clean = mosq_test.gen_connect("flipflop-test", keepalive=keepalive, clean_session=True)
connack_packet_sub = mosq_test.gen_connack(rc=0)
connect_packet_pub = mosq_test.gen_connect("flipflop-test-pub", keepalive=keepalive)
connack_packet_pub = mosq_test.gen_connack(rc=0)
mid=1
subscribe_packet = mosq_test.gen_subscribe(mid, "flipflop/test", 1)
suback_packet = mosq_test.gen_suback(mid, 1)
mid=1
publish_packet = mosq_test.gen_publish("flipflop/test", qos=1, mid=mid, payload="message")
puback_packet = mosq_test.gen_puback(mid)
port = mosq_test.get_port()
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
示例7:
import socket
import time
import inspect, os, sys
# From http://stackoverflow.com/questions/279237/python-import-a-module-from-a-folder
cmd_subfolder = os.path.realpath(os.path.abspath(os.path.join(os.path.split(inspect.getfile( inspect.currentframe() ))[0],"..")))
if cmd_subfolder not in sys.path:
sys.path.insert(0, cmd_subfolder)
import mosq_test
rc = 1
mid = 53
keepalive = 60
connect_packet_ok = mosq_test.gen_connect("will-acl-test", keepalive=keepalive, will_topic="ok", will_payload="should be ok")
connack_packet_ok = mosq_test.gen_connack(rc=0)
connect_packet = mosq_test.gen_connect("will-acl-test", keepalive=keepalive, will_topic="will/acl/test", will_payload="should be denied")
connack_packet = mosq_test.gen_connack(rc=5)
broker = subprocess.Popen(['../../src/mosquitto', '-c', '07-will-acl-denied.conf'], stderr=subprocess.PIPE)
try:
time.sleep(0.5)
sock_ok = mosq_test.do_client_connect(connect_packet_ok, connack_packet_ok, timeout=5, connack_error="connack ok")
sock = mosq_test.do_client_connect(connect_packet, connack_packet)
rc = 0
sock.close()
sock_ok.close()
finally:
示例8: open
with open(filename, 'w') as f:
f.write("port %d\n" % (port))
f.write("persistence true\n")
f.write("persistence_file mosquitto-%d.db\n" % (port))
port = mosq_test.get_port()
conf_file = os.path.basename(__file__).replace('.py', '.conf')
write_config(conf_file, port)
rc = 1
mid = 530
keepalive = 60
connect_packet = mosq_test.gen_connect(
"persitent-subscription-test", keepalive=keepalive, clean_session=False,
)
connack_packet = mosq_test.gen_connack(rc=0)
connack_packet2 = mosq_test.gen_connack(rc=0, resv=1) # session present
subscribe_packet = mosq_test.gen_subscribe(mid, "subpub/qos1", 1)
suback_packet = mosq_test.gen_suback(mid, 1)
mid = 300
publish_packet = mosq_test.gen_publish("subpub/qos1", qos=1, mid=mid, payload="message")
puback_packet = mosq_test.gen_puback(mid)
mid = 1
publish_packet2 = mosq_test.gen_publish("subpub/qos1", qos=1, mid=mid, payload="message")
if os.path.exists('mosquitto-%d.db' % (port)):
os.unlink('mosquitto-%d.db' % (port))