-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
26 lines (20 loc) · 778 Bytes
/
main.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
'use strict';
const MulticastConnection = require('./multicast-connection');
const NodeFinder = require('./node-finder');
var address = '239.255.255.250';
var port = 6024;
function connect (connection, object, type) {
object.sendMessage = (msg) => { connection.sendObject({ type: type, payload: msg}); };
connection.handlers[type] = (msg, rinfo) => { object.recvMessage(msg, rinfo); };
}
var mconn = new MulticastConnection(address, port);
var nodefinder = new NodeFinder();
connect(mconn, nodefinder, "node-finder");
setInterval(showNodes, 6000);
function showNodes () {
var nodes = nodefinder.listNodes();
console.log("Known nodes: %d", Object.keys(nodes).length);
for (var key in nodes) {
console.log(" %s: %s", key, nodes[key]);
}
}