Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var mqtt = require('mqtt');
var client1 = mqtt.connect('mqtt://172.20.0.2');
var client2 = mqtt.connect('mqtt://172.20.0.3');
client1.on('connect', function () {
client1.subscribe("foo")
});
client1.on('message', function (topic, message) {
console.log("got msg", topic, message.toString());
});
client1.on("error", (e) => console.error(e));
client2.on("error", (e) => console.error(e));
setInterval(() => client2.publish("foo", "bar"), 1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment