Skip to content
Advertisement

Why cannot I connect to hivemq broker the socket keep on getting closed when I try to reconnect?

I have wriiten to publish a rfid value and while subscribing inside javascript, the socket connection is lost and I have attached the screenshot of my console.

value.php

JavaScript

enter image description here

I am trying to connect using hivemq broker and using port number of 8000 but it’s not connecting.

app.js

JavaScript

Advertisement

Answer

First, are you 100% sure that port 8000 is configured to support MQTT over Websockets.

Second, you appear to have a hard coded clientId value, with this you will only be able to have 1 client connected at a time. EVERY Page needs to have a unique clientId, if you try and connect 2 clients with the same clientId (2 or more instances of the page in any browser) will kick the other one off the broker. ClientIds MUST be globally unique.

If after you have checked the first and fixed the second you should check the broker logs to see why it may be closing the connection.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement