4336987@qq.com
4336987@qq.com
  • 发布:2019-01-26 21:30
  • 更新:2019-10-14 16:52
  • 阅读:1504

为何小程序可以连接mqtt而安卓模拟器内连接老是失败呢?

分类:uni-app

为何小程序可以连接mqtt而安卓模拟器内连接老是失败呢?

import { connect } from '../common/js/mqtt.min.js'  

import Vue from "vue"  
import { connect } from '../common/js/mqtt.min.js'  
export const startMqtt = function() {  
    client = connect('wxs://www.gewuweb.com/mqtt', {  
        //port: 443,  
        clientId: Math.random().toString(16).substr(2, 8),  
        protocolVersion: 4,  
        clean: false,  
        password: "hahahaha",  
        username: "U-2",  
        //keepalive: 5,  
    })  

    client.on('connect', function () {  
   console.log('>>> connected');  
}).on('error', function(err) {  
    console.log("链接mqtt报错:"+ err)  
})  
Vue.prototype.$mqtt = client  
}
2019-01-26 21:30 负责人:无 分享
已邀请:

最佳回复

DCloud_UNI_GSQ

DCloud_UNI_GSQ

在 uni-app 中 MQTT.js 可以使用,按小程序写法即可,参考:示例

4336987@qq.com

4336987@qq.com (作者)

但我在网上找到别人的用户名密码,在安卓模拟器上又可以连接

    client = connect('wxs://mqtt.syniot.cn/mqtt', {  
        //port: 443,  
        clientId: Math.random().toString(16).substr(2, 8),  
        protocolVersion: 4,  
        clean: false,  
        password: "syniot",  
        username: "syniot",  
        //keepalive: 5,  
    })

谁能告诉我,我服务后端哪里不妥吗?为何我服务器后端MQTT小程序又可以连接,就是安卓模拟器不能连

4336987@qq.com

4336987@qq.com (作者)

会不会是uni-app在websocket通讯的时候有什么特殊限定吗?

4336987@qq.com

4336987@qq.com (作者)

海马玩模拟器报错
09:30:41.704 项目 'TestMqtt' 编译成功.
09:30:44.919 java.net.ConnectException: Connection refused: connect
09:30:44.925 at java.net.TwoStacksPlainSocketImpl.socketConnect(Native Method)
09:30:44.931 at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
09:30:44.937 at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
09:30:44.947 at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
09:30:44.947 at java.net.PlainSocketImpl.connect(Unknown Source)
09:30:44.947 at java.net.SocksSocketImpl.connect(Unknown Source)
09:30:44.947 at java.net.Socket.connect(Unknown Source)
09:30:44.947 at java.net.Socket.connect(Unknown Source)
09:30:44.948 at java.net.Socket.<init>(Unknown Source)
09:30:44.948 at java.net.Socket.<init>(Unknown Source)
09:30:44.948 at com.pandora.console.core.ConsoleLauncher.main(ConsoleLauncher.java:41)

要回复问题请先登录注册