paho.mqtt.javascript
paho.mqtt.javascript copied to clipboard
Socket error:undefined when trying to connect to a mosquitto broker
Hi,
I have a mosquitto server running on ubuntu 18.02. I've confirmed that the websocket is open and listening on the desired port (both through netstat and logs). I'm running version mosquitto 1.5.8 built with libwebsockets version 2.4 (I tried with the most recent libwebsockets version but that didn't work either). I keep getting Socket error: undefined on the paho js utility when trying to connect. I also connect fine on the default port not through a websocket. I've also connected to the websocket port using a different MQTT client app. Any help with narrowing down the issue would be appreciated!
Thanks
I just tried with Mosquitto 1.5.8 and it worked. Situations where I got a socket error:undefined:
- connecting to the wrong port
- attempting to use TLS when the Mosquitto listener was not configured for TLS (whether the other way around fails in the same way, I don't know)
Well it is definitely the right port, when I uncheck the TLS box and try to connect, the console just shows:
Wed, 17 Apr 2019 20:00:36 GMT - INFO - Connecting to Server: [Host: 192.168.4.99, Port: 9001, Path: /ws, ID: js-utility-WbH5N]
and nothing happens, may I ask how your Mosquitto broker was configured?
I added these two lines:
listener 443 protocol websockets
to the default Mosquitto config
Could you post the settings you used in the client?
Also what platform you are using for the mosquitto broker? I just re-setup a 1.5.8 mosquitto broker (basic setup, just added the websocket listener to default) on a raspberry pi stretch and ran into the same issue.
I tried on MacOS. I just tried on Ubuntu, also worked (with Mosquitto 1.5.4 as that's what I thought I remembered - I got that wrong apparently).
I used all the defaults on the utility except for turning TLS off.
So it was something very stupid, my browser (chrome) was automatically blocking external scripts from the page. disabled that and it worked.
@icraggs I'm having this problem (socket error:undefined) when I'm releasing a react native app connected to test.mosquitto.org. However, when I'm testing it on simulator it getting ok.
My stack overflow question
Thanks