Last active
April 29, 2016 08:22
-
-
Save MeoBeoI/60b9fbbdb5e3ad2f6567 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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