eclipse-paho / paho.mqtt.javascript

paho.mqtt.javascript
Other
1.16k stars 466 forks source link

Socket error:undefined when trying to connect to a mosquitto broker #193

Open IanCloutier opened 5 years ago

IanCloutier commented 5 years ago

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

icraggs commented 5 years ago

I just tried with Mosquitto 1.5.8 and it worked. Situations where I got a socket error:undefined:

IanCloutier commented 5 years ago

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?

icraggs commented 5 years ago

I added these two lines:

listener 443 protocol websockets

to the default Mosquitto config

IanCloutier commented 5 years ago

Could you post the settings you used in the client?

IanCloutier commented 5 years ago

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.

icraggs commented 5 years ago

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.

IanCloutier commented 5 years ago

So it was something very stupid, my browser (chrome) was automatically blocking external scripts from the page. disabled that and it worked.

marmundo commented 4 years ago

@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