1 | #! /usr/bin/env node
|
2 |
|
3 | var mqtt = require('../');
|
4 | var client = mqtt.connect({ port: 1883, host: "localhost", clean: true, keepalive: 0 });
|
5 |
|
6 | var sent = 0;
|
7 | var interval = 5000;
|
8 |
|
9 | function count() {
|
10 | console.log("sent/s", sent / interval * 1000);
|
11 | sent = 0;
|
12 | }
|
13 |
|
14 | setInterval(count, interval)
|
15 |
|
16 | function immediatePublish() {
|
17 | setImmediate(publish)
|
18 | }
|
19 |
|
20 | function publish() {
|
21 | sent++;
|
22 | client.publish("test", "payload", immediatePublish);
|
23 | }
|
24 |
|
25 | client.on("connect", publish);
|
26 |
|
27 | client.on("error", function() {
|
28 | console.log("reconnect!");
|
29 | client.stream.end();
|
30 | });
|