Skip to content

Instantly share code, notes, and snippets.

@adamvr
Created June 5, 2013 14:22
Show Gist options
  • Save adamvr/5714227 to your computer and use it in GitHub Desktop.
Save adamvr/5714227 to your computer and use it in GitHub Desktop.
Testing for mqttjs reconnection
var mqtt = require('./');
var client = mqtt.createClient();
client.on('connect', function() {
console.log('connected');
});
client.on('close', function() {
console.log('close, dcing:', client.disconnecting);
});
client.on('error', function(err) {
console.log(error);
});
var count = 5;
var t = setInterval(function () {
if (!count--) {
client.end();
} else {
console.log('shutting connection');
client.stream.end();
}
}, 3000);
t.unref();
var client2 = mqtt.createClient();
client2.end();
client2.on('connect', function() {
console.log('client2 connect');
});
client2.on('close', function() {
console.log('client2 close, dcing:', client2.disconnecting);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment