本文整理汇总了Python中mosq_test.start_broker函数的典型用法代码示例。如果您正苦于以下问题:Python start_broker函数的具体用法?Python start_broker怎么用?Python start_broker使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了start_broker函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: exit
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
time.sleep(0.5)
broker.terminate()
开发者ID:120991021,项目名称:mosquitto,代码行数:31,代码来源:08-ssl-connect-cert-auth-without.py
示例2:
keepalive = 60
connect_packet = mosq_test.gen_connect("retain-clear-test", keepalive=keepalive)
connack_packet = mosq_test.gen_connack(rc=0)
publish_packet = mosq_test.gen_publish("retain/clear/test", qos=0, payload="retained message", retain=True)
retain_clear_packet = mosq_test.gen_publish("retain/clear/test", qos=0, payload=None, retain=True)
mid_sub = 592
subscribe_packet = mosq_test.gen_subscribe(mid_sub, "retain/clear/test", 0)
suback_packet = mosq_test.gen_suback(mid_sub, 0)
mid_unsub = 593
unsubscribe_packet = mosq_test.gen_unsubscribe(mid_unsub, "retain/clear/test")
unsuback_packet = mosq_test.gen_unsuback(mid_unsub)
cmd = ['../../src/mosquitto', '-p', '1888']
broker = mosq_test.start_broker(filename=os.path.basename(__file__), cmd=cmd)
try:
sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=4)
# Send retained message
sock.send(publish_packet)
# Subscribe to topic, we should get the retained message back.
sock.send(subscribe_packet)
if mosq_test.expect_packet(sock, "suback", suback_packet):
if mosq_test.expect_packet(sock, "publish", publish_packet):
# Now unsubscribe from the topic before we clear the retained
# message.
sock.send(unsubscribe_packet)
if mosq_test.expect_packet(sock, "unsuback", unsuback_packet):
开发者ID:AddictXQ,项目名称:mosquitto,代码行数:31,代码来源:04-retain-qos0-clear.py
示例3:
keepalive = 60
connect_packet = mosq_test.gen_connect("bridge-reconnect-test", keepalive=keepalive)
connack_packet = mosq_test.gen_connack(rc=0)
mid = 180
subscribe_packet = mosq_test.gen_subscribe(mid, "bridge/#", 0)
suback_packet = mosq_test.gen_suback(mid, 0)
publish_packet = mosq_test.gen_publish("bridge/reconnect", qos=0, payload="bridge-reconnect-message")
try:
os.remove('mosquitto.db')
except OSError:
pass
cmd = ['../../src/mosquitto', '-p', '1888']
broker = mosq_test.start_broker(filename=os.path.basename(__file__), cmd=cmd)
local_cmd = ['../../src/mosquitto', '-c', '06-bridge-reconnect-local-out.conf']
local_broker = mosq_test.start_broker(cmd=local_cmd, filename=os.path.basename(__file__)+'_local1')
if os.environ.get('MOSQ_USE_VALGRIND') is not None:
time.sleep(5)
else:
time.sleep(0.5)
local_broker.terminate()
local_broker.wait()
if os.environ.get('MOSQ_USE_VALGRIND') is not None:
time.sleep(5)
else:
time.sleep(0.5)
local_broker = mosq_test.start_broker(cmd=local_cmd, filename=os.path.basename(__file__)+'_local2')
if os.environ.get('MOSQ_USE_VALGRIND') is not None:
开发者ID:AddictXQ,项目名称:mosquitto,代码行数:31,代码来源:06-bridge-reconnect-local-out.py
示例4: str
env['PYTHONPATH'] = '../../lib/python:'+pp
rc = 1
keepalive = 60
connect_packet = mosq_test.gen_connect("no-psk-test-client", keepalive=keepalive)
connack_packet = mosq_test.gen_connack(rc=0)
mid = 1
subscribe_packet = mosq_test.gen_subscribe(mid, "psk/test", 0)
suback_packet = mosq_test.gen_suback(mid, 0)
publish_packet = mosq_test.gen_publish(topic="psk/test", payload="message", qos=0)
bridge_cmd = ['../../src/mosquitto', '-c', '08-tls-psk-bridge.conf2']
broker = mosq_test.start_broker(filename=os.path.basename(__file__), use_conf=True, port=port1)
bridge = mosq_test.start_broker(filename=os.path.basename(__file__)+'_bridge', cmd=bridge_cmd, port=port3)
pub = None
try:
sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=30, port=port1)
sock.send(subscribe_packet)
if mosq_test.expect_packet(sock, "suback", suback_packet):
pub = subprocess.Popen(['./c/08-tls-psk-bridge.test', str(port3)], env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if pub.wait():
raise ValueError
(stdo, stde) = pub.communicate()
if mosq_test.expect_packet(sock, "publish", publish_packet):
rc = 0
开发者ID:PierreF,项目名称:mosquitto,代码行数:31,代码来源:08-tls-psk-bridge.py
示例5: write_config
write_config(conf_file, port)
rc = 1
keepalive = 10
connect_packet = mosq_test.gen_connect("connect-uname-pwd-test", keepalive=keepalive, username="readonly")
connack_packet = mosq_test.gen_connack(rc=0)
mid = 53
subscribe_packet = mosq_test.gen_subscribe(mid, "qos0/test", 0)
suback_packet = mosq_test.gen_suback(mid, 0)
mid_fail = 54
subscribe_packet_fail = mosq_test.gen_subscribe(mid_fail, "#", 0)
suback_packet_fail = mosq_test.gen_suback(mid_fail, 0x80)
broker = mosq_test.start_broker(filename=os.path.basename(__file__), use_conf=True, port=port)
try:
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):
sock.send(subscribe_packet_fail)
if mosq_test.expect_packet(sock, "suback", suback_packet_fail):
rc = 0
sock.close()
finally:
os.remove(conf_file)
broker.terminate()
broker.wait()
开发者ID:PierreF,项目名称:mosquitto,代码行数:31,代码来源:09-plugin-auth-acl-sub.py
示例6:
env["PYTHONPATH"] = "../../lib/python:" + pp
rc = 1
keepalive = 60
connect_packet = mosq_test.gen_connect("no-psk-test-client", keepalive=keepalive)
connack_packet = mosq_test.gen_connack(rc=0)
mid = 1
subscribe_packet = mosq_test.gen_subscribe(mid, "psk/test", 0)
suback_packet = mosq_test.gen_suback(mid, 0)
publish_packet = mosq_test.gen_publish(topic="psk/test", payload="message", qos=0)
bridge_cmd = ["../../src/mosquitto", "-c", "08-tls-psk-bridge.conf2"]
broker = mosq_test.start_broker(filename=os.path.basename(__file__))
bridge = mosq_test.start_broker(filename=os.path.basename(__file__) + "_bridge", cmd=bridge_cmd, port=1890)
pub = None
try:
sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=30)
sock.send(subscribe_packet)
if mosq_test.expect_packet(sock, "suback", suback_packet):
pub = subprocess.Popen(["./c/08-tls-psk-bridge.test"], env=env, stdout=subprocess.PIPE)
if pub.wait():
raise ValueError
if mosq_test.expect_packet(sock, "publish", publish_packet):
rc = 0
sock.close()
开发者ID:yongli3,项目名称:mosquitto,代码行数:31,代码来源:08-tls-psk-bridge.py
注:本文中的mosq_test.start_broker函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论