Mqtt.js: I can't connect the server in vuejs

Created on 21 Jun 2018  路  6Comments  路  Source: mqttjs/MQTT.js

I just use the simple ep:

    var client = mqtt.connect("mqtt://test.mosquitto.org");

    client.on("connect", function() {
      client.subscribe("presence");
      client.publish("presence", "Hello mqtt");
    });

    client.on("message", function(topic, message) {
      // message is Buffer
      console.log(message.toString());
      client.end();
    });

this code writes in created() function in vue-cil project , but got a error:

stream.js?b72e:64 WebSocket connection to 'ws://test.mosquitto.org/' failed: Error during WebSocket handshake: Unexpected response code: 200

is there something wrong?

Thanks in advance.

Most helpful comment

@anthrogan adding port 1883 is not useful .
got a error:
stream.js?b72e:64 WebSocket connection to 'ws://test.mosquitto.org:1883/' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET,

anyway,tks a lot.

All 6 comments

You need to supply a port with the connection url. "mqtt://test.mosquitto.org:1883"

@anthrogan adding port 1883 is not useful .
got a error:
stream.js?b72e:64 WebSocket connection to 'ws://test.mosquitto.org:1883/' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET,

anyway,tks a lot.

the same problem

set broker protocol websockets

@sueblue I am having this same error in vue.js. Were you able to resolve this?
Would love to hear the solution :)

@Haider8 make sure your broke use the websockets protocol. not the tcp

Was this page helpful?
0 / 5 - 0 ratings

Related issues

markcnunes picture markcnunes  路  7Comments

bicccio picture bicccio  路  3Comments

sublimator picture sublimator  路  8Comments

hijklmno picture hijklmno  路  7Comments

jeffdare picture jeffdare  路  9Comments