forked from moscajs/aedes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
40 lines (32 loc) · 938 Bytes
/
example.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
31
32
33
34
35
36
37
38
39
40
'use strict'
var aedes = require('./aedes')()
var server = require('net').createServer(aedes.handle)
var httpServer = require('http').createServer()
var ws = require('websocket-stream')
var port = 1883
var wsPort = 8888
server.listen(port, function () {
console.log('server listening on port', port)
})
ws.createServer({
server: httpServer
}, aedes.handle)
httpServer.listen(wsPort, function () {
console.log('websocket server listening on port', wsPort)
})
aedes.on('clientError', function (client, err) {
console.log('client error', client.id, err.message, err.stack)
})
aedes.on('publish', function (packet, client) {
if (client) {
console.log('message from client', client.id)
}
})
aedes.on('subscribe', function (subscriptions, client) {
if (client) {
console.log('subscribe from client', subscriptions, client.id)
}
})
aedes.on('client', function (client) {
console.log('new client', client.id)
})