简体   繁体   中英

Paho Websocket Connection Closes Upon Second Connection

I have built an MQTT server to test of M2M messages and I built a small Javascript application using Paho and I am able to connect, subscribe, and publish messages on a single connection. However, once I start up a new tab or browser, the first connection closes. I am not sure why and I happen when I have a new connection, even from another computer.

You can not use hard coded client ids, the best option is to use a random number or millisecond timestamp based id.

eg

var clientID = "web" + new Date().getTime();

var client = new Paho.MQTT.Client('localhost',1884,clientID);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM