paho.mqtt.javascript icon indicating copy to clipboard operation
paho.mqtt.javascript copied to clipboard

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

Open IanCloutier opened this issue 5 years ago • 8 comments

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

IanCloutier avatar Apr 17 '19 16:04 IanCloutier

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)

icraggs avatar Apr 17 '19 19:04 icraggs

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?

IanCloutier avatar Apr 17 '19 20:04 IanCloutier

I added these two lines:

listener 443 protocol websockets

to the default Mosquitto config

icraggs avatar Apr 17 '19 20:04 icraggs

Could you post the settings you used in the client?

IanCloutier avatar Apr 17 '19 20:04 IanCloutier

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.

IanCloutier avatar Apr 18 '19 15:04 IanCloutier

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.

icraggs avatar Apr 18 '19 19:04 icraggs

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

IanCloutier avatar Apr 18 '19 20:04 IanCloutier

@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

marmundo avatar Mar 27 '20 23:03 marmundo