测试订阅和发布
测试
一、开启另一个终端窗口,运行订阅程序mosquitto_sub:
注意:
消息推送的发布和订阅要有主题,选项[-t] 主题,即:mosquitto -t 主题
如需指定用户名称则加选项[-i] 用户名,即:mosquitto_sub -t 主题 -i 订阅端
mosquitto_sub-tmqtt
1
二、开启另一个终端窗口,运行发布程序mosquitto_pub:
指定消息推送的主题,发布端用户名和消息:
mosquitto_pub -t 主题 -i 发布端 -h 主机 -m 你好
*注意:如果消息中间有空格则消息要用引号括起来。
mosquitto_pub-hlocalhost-tmqtt-m"hello world."
=================================================================
账号:chisj 密码123456
发布:
mosquitto_pub -h 192.168.0.1 -t mtopic -u chisj -P 123456 -m "test"
订阅:
mosquitto_sub -h 192.168.0.1 -t mtopic -u chisj -P 123456
网友评论