Files
HarmonyOS--waterapp/mqtt-backend/node_modules/aedes/benchmarks/throughputCounter.js
T
2026-07-13 12:06:16 +08:00

24 lines
451 B
JavaScript

#! /usr/bin/env node
const mqtt = require('mqtt')
const client = mqtt.connect({ port: 1883, host: 'localhost', clean: true, encoding: 'binary', keepalive: 0 })
const interval = 5000
let counter = 0
function count () {
console.log('received/s', counter / interval * 1000)
counter = 0
}
setInterval(count, interval)
client.on('connect', function () {
count()
this.subscribe('test')
this.on('message', function () {
counter++
})
})