Skip to content

Instantly share code, notes, and snippets.

@MeoBeoI
Last active April 29, 2016 08:22
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 MeoBeoI/60b9fbbdb5e3ad2f6567 to your computer and use it in GitHub Desktop.
Save MeoBeoI/60b9fbbdb5e3ad2f6567 to your computer and use it in GitHub Desktop.
var mqtt = require('mqtt');
// Connect to Broker
var client = mqtt.connect('mqtt://test.mosquitto.org');
client.on('connect', function () {
client.subscribe('chatroom'); // Subcribre to a `chatroom` topic
client.publish('chatroom', 'Hello mqtt'); // Publish a message to `chatroom` topic
});
client.on('message', function (topic, message) {
// message is Buffer => parse into String
console.log(message.toString());
client.end();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment