-
Notifications
You must be signed in to change notification settings - Fork 0
/
minimal.js
54 lines (47 loc) · 1.41 KB
/
minimal.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*!
* minimal.js
* Minimalistic example to get the advertising and discovery up and running.
*
* Run this example on multiple hosts on your loca network and watch the console output.
*/
var
NetworkServiceDiscover = require('../src/network-service-discover'),
nsd = NetworkServiceDiscover();
;
nsd.start(
{
// Udp port to send and receive packets
port: 7691,
// Send broadcast packet every 15 seconds.
advertise: 15,
// Remove services from the list when they have not been received for 60 seconds.
purge: 60,
// Array of services we want to advertise on the network.
//
// name {string} - Name of the service
// port {integer} - Udp port the service listening on
// secure {bool} - True if secured aka. SSL connection
// path {string} - Path for the RESTfull api
service: [
{ name: 'WarehouseCatalog', port: 45241, secure: false, path: '/api/whc/V01/' },
],
// Callback function called in case of an error.
error: function(err) {
err && console.log(err);
},
// Callback function called when new services are discovered.
change: function(data) {
console.log(data);
}
},
function(socket, err) {
err && console.log(err);
}
);
// Every minute output the list of discovered services to the console.
setInterval(
function() {
console.log('Discovered:', nsd.getServices());
},
60000
);