Within my app.js file:
const mqtt = require('mqtt')
const 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 successfully connected to both hivemq-cli and the hivemq server. I then created a new topic named testTopic
under the Test1
subscriptions and allowed another user to subscribe to it.
https://i.sstatic.net/lv3Rk.png
Using hivemq-cli, everything seemed fine as shown in my terminal:
testTopic3@localhost> sub -t testTopic -s
Hello
Hello
Hello
Hello
Hello
Hello
Hi
Hi
Hi
However, upon running npm start
, my web application reported an error stating: "Firefox can't establish a connection to the server at ws://localhost:1883/", and returned nothing.
I have been struggling with this issue for a day now, so any assistance would be greatly appreciated. Thank you!