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.
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
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.