31 lines
808 B
Markdown
31 lines
808 B
Markdown
npm install aedes --save
|
|
npm install aedes-cli --global
|
|
npm install express aedes ws
|
|
|
|
|
|
|
|
```
|
|
const aedes = require('aedes')();
|
|
const server = require('net').createServer(aedes.handle);
|
|
const port = 1883;
|
|
|
|
server.listen(port, function () {
|
|
console.log('Aedes broker started and listening on port ', port);
|
|
});
|
|
|
|
aedes.on('client', function (client) {
|
|
console.log('Client Connected:', client.id);
|
|
});
|
|
|
|
aedes.on('clientDisconnect', function (client) {
|
|
console.log('Client Disconnected:', client.id);
|
|
});
|
|
|
|
aedes.on('publish', function (packet, client) {
|
|
console.log('Published:', packet.payload.toString());
|
|
});
|
|
```
|
|
|
|
mosquitto_pub -h localhost -p 1883 -t test-sub -m "Server Push"
|
|
|
|
mosquitto_pub -h localhost -p 1883 -t test-sub -m "Server Push" -u "test_user" -P "test_pass" |