1. 引入mosquitto仓库并更新
$sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa
$sudo apt-get update
$sudo apt-get install mosquitto
$sudo apt-get install libmosquitto-dev
$sudo apt-get install mosquitto-clients
$sudo service mosquitto status
$mosquitto_sub -h localhost -t "mqtt" -v
$mosquitto_pub -h localhost -t "mqtt" -m "Hello MQTT"
现在你会看到消息被显示在前一个终端上了.
7. 网络测试(test.mosquitto.org)
从test.mosquitto.org订阅所有主题,任何人发布的任何消息你都可以收到,你会看到大量有趣消息滚动在你的屏幕上。你也可以发布一些有趣的消息,所有订阅的人也同样会收到。
$mosquitto_sub -h test.mosquitto.org -t "#" -v
$mosquitto_sub -h test.mosquitto.org -t "msg_only_from_me" -v
$mosquitto_pub -h test.mosquitto.org -t "msg_only_from_me" -m "My cat is Luna"
test.mosquitto.org 支持加密和不加密MQTT消息模式,也支持用TCP或者Websocket作为承载,可以通过wireshark抓包来观察不同的包格式.
mosquitto man page:
https://mosquitto.org/documentation/
转载地址:http://blog.csdn.net/swedenfeng/article/details/53510048