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

how can i reconnect it?

Open tianzhenjiu opened this issue 7 years ago • 8 comments

When the connection is lost, the function onConnectionLost will be called, but how do I reconnect?

tianzhenjiu avatar Dec 03 '18 07:12 tianzhenjiu

You can call connect within the connection lost callback

icraggs avatar Dec 03 '18 11:12 icraggs

when reconnect is it still use old tcp port? and then three-way handshake to establish a connection?

tianzhenjiu avatar Dec 04 '18 01:12 tianzhenjiu

i find in chrome will use same tcp port,but in firfox will use different tcp port. is right?

tianzhenjiu avatar Dec 04 '18 03:12 tianzhenjiu

There are two ways of reconnecting: explicitly in the connection lost callback, and also using automatic reconnect (in the connect options). You should use one or the other, not both.

There should be no difference in the behaviour between Firefox and Chrome, as far as I'm aware.

icraggs avatar Dec 04 '18 11:12 icraggs

ok,thank u very much

tianzhenjiu avatar Dec 06 '18 02:12 tianzhenjiu

@icraggs I've tried the reconnect property, but it doesn't always seem to reconnect. For example most of the times on network change or network break it doesn't automatically reconnect.

I either have to manually reload the page or turn the wifi off and on again in my laptop for it to work.

Any idea why that might be happening? And is there any other way that might work?

mridah avatar Jun 20 '20 03:06 mridah

@mridah I've seen the same issue on my end. Did you find a way to figure a way out?

zainsyedz avatar Apr 01 '21 06:04 zainsyedz

@mridah when the ping timeout,it will trigger to reconnect network change or network break can not notify mqtt.JS

tianzhenjiu avatar Apr 05 '21 04:04 tianzhenjiu