鍍金池/ 問答/Java  HTML/ 微信小程序使用MQTT報錯求解

微信小程序使用MQTT報錯求解

var Paho = require('../../paho-mqtt');

var client = new Paho.Client('IP地址',端口號, "clientId");

Page({
data:{},
publishMessage: function () {

var message = new Paho.Message('hello world');
message.destinationName = "test/topic"; 
client.send(message);

},
onLoad: function () {

client.onMessageArrived = function (msg) {
  wx.showToast({
    title: msg.payloadString
  });
}
client.onConnectionLost = function (responseObject) {
  if (responseObject.errorCode !== 0) {
    console.log("onConnectionLost:" + responseObject.errorMessage);
  }
}
client.connect({
  useSSL: true,
  cleanSession: false,
  keepAliveInterval: 60,
  userName:123456,
  password:1233456,
  onSuccess: function () {
    console.log('connected');
    client.subscribe("test/topic", {
      qos: 1
    });
  }
});

}
})

現(xiàn)在報錯如下:
WebSocket connection to 'wss://IP地址,/mqtt' failed: Error in connection establishment: net::ERR_CONNECTION_RESET

回答
編輯回答
涼汐

var client = new Paho.Client('IP地址',端口號, "clientId");
IP地址 這里改成你的IP
端口號 這里改成你的端口

2017年5月25日 03:18