nowox
nowox

Reputation: 29066

How to connect to a MQTT Broker with Websockets?

I have a test.html file that I open with Chrome:

<html>   
<head>
    <script src="https://unpkg.com/mqtt/dist/mqtt.min.js"></script>
</head>

<body>
    <script>
        var client = mqtt.connect('ws://broker.hivemq.com:8000')
        client.subscribe("mqtt/demo")

        client.on("message", function (topic, payload) {
            alert([topic, payload].join(": "))
            client.end()
        })

        client.publish("mqtt/demo", "hello world!")
    </script>
</body>
</html>

Unfortunately I have this error:

mqtt.min.js:1 WebSocket connection to 'ws://broker.hivemq.com:8000/' failed: Connection closed before receiving a handshake response

I also tried with mqtt:// and it does not work. Any idea?

Upvotes: 1

Views: 2589

Answers (1)

wivwiv
wivwiv

Reputation: 263

This server has been stopped or down and cannot be accessed. Please use

ws://broker.emqx.io:8083/mqtt

or

ws://broker.mqttdashboard.com:8000/mqtt

to try

Upvotes: 4

Related Questions