文章目录
一、mosquitto搭建
1.1 mosquitto介绍
mosquitto下载地址:https://mosquitto.org/download/
Eclipse Mosquitto是一个开源(EPL/EDL许可)消息代理(broker),它实现了MQTT协议版本5.0、3.1.1和3.1。Mosquito重量轻,适用于从低功耗单板计算机到完整服务器的所有设备。
1.2 使用mosquitto在windows下创建一个mqtt broker
step1)使能mosquitto服务
step2)配置mosquitto
# MQTT协议端口号
listener 1883
# 启用WebSocket支持
listener 9001
protocol websockets
# 订阅主题持久化
persistence true
persistence_location D:\software\mosquitto\data
# 开启日志记录
log_dest file D:\software\mosquitto\mosquitto.log
log_type all
# 开启密码验证
password_file D:\software\mosquitto\pwfile.example
allow_anonymous false
step3)创建访问mqtt broker的账户
mosquitto_passwd.exe用于生成连接mqtt broker的用户名和密码,下面的命令表示向pwfile.example文件追加一个“myAccount”账户,在client中可以用这个账户和密码登录,否则会报验证失败的错误。
.\mosquitto_passwd.exe .\pwfile.example myAccount
step4)启动mqtt broker
执行下面的命令可以启动一个mqtt服务器
.\mosquitto.exe -v -c .\config\mosquitto.conf
二、mqtt网络包分析
client发布一条消息后,mosquitto由于协议错误而主动发送FIN包断开连接。
查看mosquittop的日志,断开原因是协议错误。
三、参考
Windows环境下安装配置Mosquitto服务及入门操作介绍
Windows 操作系统安装Mosquitto (MQTT)及测试