In my app.js:
var mqtt = require('mqtt')
var client = mqtt.connect('mqtt://localhost:1883')
topic = 'testTopic'
client.on('connect', ()=> {
client.subscribe(topic)
})
client.on('message', function (topic, message) {
console.log(message.toString())
})
I connected in hivemq-cli and hivemq server, then create a new topic testTopic
in Test1
subscriptions, and let another subscribe to testTopic
In hivemq-cli it's all ok, in my terminal:
testTopic3@localhost> sub -t testTopic -s
Hello
Hello
Hello
Hello
Hello
Hello
Hi
Hi
Hi
But when I use npm start
, my web app said that: Firefox can't establish a connection to the server at ws://localhost:1883/, and return nothing.
I've been in this trouble for a day, so I'm very looking for some helps. Many thanks!