Mosquitto2.0.12及以上版本 Websocket 不能连接

最近要做消息订阅,做一点技术储备,在Download | Eclipse Mosquitto下载目前最新版2.0.14,如图:

安装后配置用户(pwfile.example)、 权限(aclfile.example)以及端口协议:

listener 1883 0.0.0.0
protocol mqtt

listener 1884 0.0.0.0
protocol websockets

启动服务

新建html访问总是提示:

Error during WebSocket handshake: net::ERR_CONNECTION_RESET

mqttws31.js:979 WebSocket connection to 'ws://ip:1884/mqtt' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET

尝试很多方法终究还是不能解决,但是使用命令行发布订阅是可以的:

发布:

订阅:

接着查找资料,终于在Anonymous setting for websockets is being ignored · Issue #2459 · eclipse/mosquitto · GitHub

 找到答案,修改配置如下:

listener 1884 0.0.0.0
protocol websockets
socket_domain ipv4

listener 1884 ::

socket_domain ipv6

protocol websockets

原因:2.0.12及以上版本,配置websocket时,必须添加socket_domain配置项,来指定是 ipv4 还是 ipv6

终于解决了此问题,html也可以链接订阅消息了:

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值