









Eclipse Mosquitto版本 去官网下载 Windows 安装包:https://mosquitto.org/download/
下载 mosquitto-2.x.x-install-windows-x64.exe,安装时选择安装为服务(Install as a Windows service)。

用管理员运行windows powershell
输入 net start mosquitto


# 或 net stop mosquitto
编辑配置文件 D:\Program Files\Mosquitto\mosquitto.conf:
# 监听端口
listener 1883
# 允许匿名连接(开发阶段)
allow_anonymous true
# 如果后续需要账号密码认证:
# allow_anonymous false
# password_file C:\mosquitto\config\pwfile
# WebSockets 支持(可选,方便前端调试)
listener 9001
protocol websockets
订阅话题
订阅(sub = subscribe):
& "D:\Program Files\Mosquitto\mosquitto_sub.exe" -t "test/topic" -v
& "D:\Program Files\Mosquitto\mosquitto_sub.exe" -t "speek/topic" -v
发布话题
发布(pub = publish):
& "D:\Program Files\Mosquitto\mosquitto_pub.exe" -t "test/topic" -m "出发"
& "D:\Program Files\Mosquitto\mosquitto_pub.exe" -t "speek/topic" -m "说话了"
区别就在 sub 和 pub 两个字母。记住:sub 收,pub 发。
打开两个windows powershell



此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。