【问题标题】:MQTT Websocket connection failed in CloudMQTTCloudMQTT 中的 MQTT Websocket 连接失败
【发布时间】:2017-06-19 08:08:56
【问题描述】:

我收到以下错误。

到“wss://m12.cloudmqtt.com:39297/mqtt”的 WebSocket 连接失败:>连接建立中的错误:net::ERR_CONNECTION_TIMED_OUT

我正在尝试从 paho 客户端连接到 cloudmqtt。

    client = new Paho.MQTT.Client("m12.cloudmqtt.com", Number(39297),    "client_1");
    // set callback handlers
    client.onConnectionLost = onConnectionLost;
    client.onMessageArrived = onMessageArrived;

    // connect the client
    var options = {
            useSSL: true,
            userName: "wRRDCvty@q",
            password: "lM#$Ffg67OR",
            cleanSession: true,
            onSuccess:onConnect,
            onFailure:doFail
          }

    //client.connect({onSuccess:onConnect});
    client.connect(options);

    // called when the client connects
    function onConnect() {
      // Once a connection has been made, make a subscription and send a       message.
     debugger;
        console.log("onConnect");
      client.subscribe("outTopic");
      message = new Paho.MQTT.Message("Hello");
      message.destinationName = "World";
      client.send(message);
    }

    function doFail(){
        debugger;
        console.log("dofail");
    }
    // called when the client loses its connection
    function onConnectionLost(responseObject) {
      if (responseObject.errorCode !== 0) {
        console.log("onConnectionLost:"+responseObject.errorMessage);
      }
    }

    // called when a message arrives
    function onMessageArrived(message) {
      console.log("onMessageArrived:"+message.payloadString);
      var msg = message.payloadString;
      debugger;

    }

当我执行程序时触发doFail()函数? 可能是什么问题?

【问题讨论】:

    标签: javascript websocket client mqtt paho


    【解决方案1】:

    配置了防火墙,它工作正常。

    【讨论】:

      猜你喜欢
      • 2015-09-14
      • 1970-01-01
      • 2018-12-19
      • 1970-01-01
      • 2022-10-17
      • 2016-04-20
      • 2013-12-17
      • 2016-05-13
      相关资源
      最近更新 更多