vue使用mqtt,tcp协议头的坑

受到大佬的启发 物联网之MQTT 保姆来了 MQTT原理 以及如何进行调试_哔哩哔哩_bilibili

从头说吧,刚开始我做了个android项目用到了mqtt,然后在那儿我用的mqtt地址为tcp://xxxxxx:1883 ,成功跑通了;后来我又做vue项目也需要用到mqtt,发现按着原先android项目的地址填tcp://xxxxxx:1883一直报错,控制台打印的地址总把tcp替换成ws,后来折腾了老久才发现,将原地址换成wss://xxxxx:8084/mqtt就行了,下面贴代码和截图

android项目里的(正确代码):

原android项目访问的格式

《vue使用mqtt,tcp协议头的坑》

 android关键代码截图

《vue使用mqtt,tcp协议头的坑》

 

vue项目里的(正确代码)· 

vue操作mqtt的格式                                                                                                                                      

《vue使用mqtt,tcp协议头的坑》

vue关键代码截图(mqtt官网的例子) 

《vue使用mqtt,tcp协议头的坑》

《vue使用mqtt,tcp协议头的坑》

 刚开始vue控制台报错代码

1.

pages-Me-Me_01.js:10304 WebSocket connection to ‘ws://XXXXX:1883/’ failed: Error during WebSocket handshake: Unexpected response code: 403

2.

Mixed Content: The page at ‘<URL>’ was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint ‘ws:<URL>/’. This endpoint should be available via WSS. Insecure access is deprecated.
13Connecting to a non-secure WebSocket server from a secure origin is deprecated.

控制台都给提示wss了,我还鼓捣老久…..哭

    原文作者:马哈小弟弟
    原文地址: https://blog.csdn.net/weixin_49446194/article/details/122944151
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞