我正在'iot.eclipse.org'上运行mosquitto代理。从我的应用服务器发布一些命令以代理代理后,客户端将断开连接并连续调用reconnect和close方法,但是除非重新启动服务器,否则不会再次连接。连接断开后,我希望它再次重新连接。 我的代码如下:
var options = {
host: 'iot.eclipse.org',
port: 1883,
};
var client = mqtt.connect(options);
client.on('connect', function (e) {
console.log("client is connected");
client.publish(topic, message,callback);
});
client.on("reconnect", function() {
console.log("client is reconnected",JSON.stringify());
})
client.on("error", function(err) {
console.log("error from client --> ", err);
})
client.on("close", function(e) {
console.log("client is closed",JSON.stringify(options),JSON.stringify(e));
})
client.on("offline", function(err) {
console.log("client is offline");
});
client.on('message', function (topic, message) {
console.log('*********');
console.log(message.toString());
})