Skip to content

Instantly share code, notes, and snippets.

@muka
Created August 8, 2018 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muka/c98db8705dceae277187791691aac977 to your computer and use it in GitHub Desktop.
Save muka/c98db8705dceae277187791691aac977 to your computer and use it in GitHub Desktop.
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