-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
30 lines (25 loc) · 783 Bytes
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
var mqtt = require('mqtt');
var topicMatch = require('./tools').topicMatch;
var tools = require('./tools');
var client = mqtt.connect('mqtt://localhost');
var config = tools.readConfiguration('config.json');
var onReply = require('./tools').onReply;
client.request = require('./tools').request;
console.log(config);
client.on('connect', function (topic, message) {
client.request('server', 'pang', function (message) {
console.log('callback foshissle');
});
client.request('server', 'pang', function (message) {
console.log(message.toString());
});
});
client.on('message', function (topic, message) {
if (topicMatch(topic, '+/response/#')) {
onReply.apply(this, arguments);
}
});
process.on('SIGINT', function () {
client.end();
process.exit();
});