paho.mqtt.javascript
paho.mqtt.javascript copied to clipboard
Failed to connect: AMQJS0007E Socket error:undefined with Mosquitto Broker
I have installed Mosquitto Broker. Netstat -an confirms the service is listening on port 1883.
I am using the latest Paho clients js utility (master branch) to connect to my LAN IP address (192.168.2.11).
I have tried both with/without the /ws path.
Here is the output from console.log.
Connecting to Server: Hostname: 192.168.2.11 . Port: 1883 . Path: /ws . Client ID: javascript-client mqttws31.js:979 WebSocket connection to 'ws://192.168.2.11:1883/ws' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET Paho.MQTT.ClientImpl._doConnect @ mqttws31.js:979 Paho.MQTT.ClientImpl.connect @ mqttws31.js:849 Client.connect @ mqttws31.js:1799 connect @ utility.js:161 connectionToggle @ utility.js:95 onclick @ index.html:89 mqttws31.js:977 WebSocket connection to 'ws://192.168.2.11:1883/ws' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET Paho.MQTT.ClientImpl._doConnect @ mqttws31.js:977 Paho.MQTT.ClientImpl._disconnected @ mqttws31.js:1457 Paho.MQTT.ClientImpl._on_socket_error @ mqttws31.js:1345 (anonymous) @ mqttws31.js:157 utility.js:40 Failed to connect utility.js:125 Connecting to Server: Hostname: 192.168.2.11 . Port: 1883 . Path: /mqtt . Client ID: javascript-client mqttws31.js:979 WebSocket connection to 'ws://192.168.2.11:1883/mqtt' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET Paho.MQTT.ClientImpl._doConnect @ mqttws31.js:979 Paho.MQTT.ClientImpl.connect @ mqttws31.js:849 Client.connect @ mqttws31.js:1799 connect @ utility.js:161 connectionToggle @ utility.js:95 onclick @ index.html:89 mqttws31.js:977 WebSocket connection to 'ws://192.168.2.11:1883/mqtt' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET Paho.MQTT.ClientImpl._doConnect @ mqttws31.js:977 Paho.MQTT.ClientImpl._disconnected @ mqttws31.js:1457 Paho.MQTT.ClientImpl._on_socket_error @ mqttws31.js:1345 (anonymous) @ mqttws31.js:157 utility.js:40 Failed to connect
Please can you guide me how to resolve this issue?
Thank you.
This client can only connect to brokers that are exposing a websocket port, you will need to make sure that your mosquitto broker has websocket support, and change the mosquitto config file to contain something like the following:
listener 1883
protocol mqtt
listener 8080
protocol websockets
Ok, thanks James for the pointer!
Actually I circled back to the readme-windows.txt (below) in the directory where I have installed mosquitto, and I came to know I need to compile the versions myself.
It would save me quite some time if someone could point me to the downloadable versions.
Thank you.
Websockets
The broker executables provided in the installers do not have Websockets support enabled. If you wish to have a version of the broker with Websockets support, you will need to compile libwebsockets version v1.3-chrome37-firefox30 yourself and mosquitto version 1.4 yourself.
Can someone please point me to an installer that has mosquitto broker websocket support?
Any support for this item?
One final try, can anyone please lend a hand?
Not sure about windows, you might want to ask on the paho or mosquitto mailing lists https://projects.eclipse.org/projects/technology.mosquitto/contact
Alternatively, you could try raising an issue here: https://github.com/eclipse/mosquitto
the docker container that uses 1.4.8 works with websockets.
I run the following command:
sudo docker run -it -p 1883:1883 -p 9001:9001 -v [PATH TO LOCAL MOSQUITTO CONF]:/mosquitto/config/mosquitto.conf eclipse-mosquitto:1.4.8
where "path to local mosquitto conf" points to a mosquitto conf file on my local system that enables websockets and assigns a port. i.e add the below to the default conf:
listener 9001
protocol websockets
I have never been able to get websockets working on mosquitto version > 1.4.8
@Nas-r I compiled the same version and Mosquitto is having trouble with permissions. On the log: mosquito can't open the door path to write. Does this happend with you?
I have docoker container that uses 1.4.14 with websockets listener 9002 protocol websockets On the log: mosquito can't open the door path to write.