kopia lustrzana https://github.com/Yakifo/amqtt
Add samples for SSL and WS
rodzic
901574f2da
commit
9428accbf7
|
@ -4,7 +4,36 @@ from hbmqtt.broker import Broker
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
broker = Broker()
|
config = {
|
||||||
|
'listeners': {
|
||||||
|
'default': {
|
||||||
|
'type': 'tcp'
|
||||||
|
},
|
||||||
|
'tcp-mqtt': {
|
||||||
|
'bind': '0.0.0.0:1883',
|
||||||
|
},
|
||||||
|
'ws-mqtt': {
|
||||||
|
'bind': '127.0.0.1:8080',
|
||||||
|
'type': 'ws'
|
||||||
|
},
|
||||||
|
'wss-mqtt': {
|
||||||
|
'bind': '127.0.0.1:8081',
|
||||||
|
'type': 'ws',
|
||||||
|
'ssl': 'on',
|
||||||
|
'certfile': 'localhost.server.crt',
|
||||||
|
'keyfile': 'server.key',
|
||||||
|
},
|
||||||
|
'tcp-ssl': {
|
||||||
|
'bind': '127.0.0.1:8883',
|
||||||
|
'ssl': 'on',
|
||||||
|
'certfile': 'localhost.server.crt',
|
||||||
|
'keyfile': 'server.key',
|
||||||
|
'type': 'tcp'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
broker = Broker(config)
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def test_coro():
|
def test_coro():
|
||||||
|
|
|
@ -17,15 +17,15 @@ config = {
|
||||||
'topic': '/will/client',
|
'topic': '/will/client',
|
||||||
'message': b'Dead or alive',
|
'message': b'Dead or alive',
|
||||||
'qos': 0x01,
|
'qos': 0x01,
|
||||||
'retain': True
|
'retain': True,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
C = MQTTClient(config=config)
|
||||||
#C = MQTTClient(config=config)
|
#C = MQTTClient()
|
||||||
C = MQTTClient()
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def test_coro():
|
def test_coro():
|
||||||
yield from C.connect('mqtts://test.mosquitto.org:8883/', cafile='mosquitto.org.crt')
|
yield from C.connect('mqtts://test.mosquitto.org/', cafile='mosquitto.org.crt')
|
||||||
tasks = [
|
tasks = [
|
||||||
asyncio.async(C.publish('a/b', b'TEST MESSAGE WITH QOS_0')),
|
asyncio.async(C.publish('a/b', b'TEST MESSAGE WITH QOS_0')),
|
||||||
asyncio.async(C.publish('a/b', b'TEST MESSAGE WITH QOS_1', qos=0x01)),
|
asyncio.async(C.publish('a/b', b'TEST MESSAGE WITH QOS_1', qos=0x01)),
|
||||||
|
|
|
@ -18,14 +18,15 @@ config = {
|
||||||
'message': b'Dead or alive',
|
'message': b'Dead or alive',
|
||||||
'qos': 0x01,
|
'qos': 0x01,
|
||||||
'retain': True
|
'retain': True
|
||||||
|
},
|
||||||
|
'capath': '.',
|
||||||
}
|
}
|
||||||
}
|
C = MQTTClient(config=config)
|
||||||
#C = MQTTClient(config=config)
|
#C = MQTTClient()
|
||||||
C = MQTTClient()
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def test_coro():
|
def test_coro():
|
||||||
yield from C.connect('ws://test.mosquitto.org:8080/')
|
yield from C.connect('wss://test.mosquitto.org:8081/', cafile='mosquitto.org.crt')
|
||||||
tasks = [
|
tasks = [
|
||||||
asyncio.async(C.publish('a/b', b'TEST MESSAGE WITH QOS_0')),
|
asyncio.async(C.publish('a/b', b'TEST MESSAGE WITH QOS_0')),
|
||||||
asyncio.async(C.publish('a/b', b'TEST MESSAGE WITH QOS_1', qos=0x01)),
|
asyncio.async(C.publish('a/b', b'TEST MESSAGE WITH QOS_1', qos=0x01)),
|
||||||
|
|
Ładowanie…
Reference in New Issue