How can i fix Connection timed out issue in mqtt?

    <script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.min.js" type="text/javascript"></script>
<script>
    // Create a client instance
    client = new Paho.MQTT.Client("broker.hivemq.com", 8000, "" , "gokden");

    // connect the client
    client.connect({onSuccess:onConnect,useSSL:true}); 

    function onConnect(){
        console.log("Connected!");
    }

</script>

This is my connection code but after 20-25 sec i saw this error: WebSocket connection to ‘wss://broker.hivemq.com:8000/’ failed: Error in connection establishment: net::ERR_CONNECTION_CLOSED

Then after 20-25 sec i saw that error again.

Hey @huntleight,

when initialising your client, you set your path variable to an empty string. Please pass “/mqtt” here.

Kind regards,
Finn

Same error here.

WebSocket connection to ‘wss://broker.hivemq.com:8000/mqtt’ failed: Error in connection establishment: net::ERR_CONNECTION_CLOSED

With wss:// you are attempting to establish a WebSocket Secure connection which is not offered on broker.hivemq.com. Please switch to using ws://.

Kind regards,
Finn

1 Like