前端调用mqtt不能使用1883端口的问题

不知为何,前端ws访问1883端口总是失败

在阿里云服务器配置了mosquitto消息服务器

添加更改配置文件 /etc/mosquitto/conf.d/myconfig.conf

 1 # 配置mosquitto支持websocket,且监听端口号为8083
 2 port 1883
 3 listener 8083
 4 protocol websockets
 5 
 6 # 关闭匿名访问,客户端必须使用用户名
 7 allow_anonymous false
 8 
 9 #指定 用户名-密码 文件
10 password_file /etc/mosquitto/pwfile.txt

这样,前端就可以用 client = mqtt.connect('ws://120.79.x.x:8083',options)  来访问了

猜你喜欢

转载自www.cnblogs.com/nuister/p/12944058.html