Browse Source

first commit

Young 6 years ago
commit
410890ff2a
4 changed files with 71 additions and 0 deletions
  1. 2 0
      .gitignore
  2. 25 0
      client.js
  3. 30 0
      index.js
  4. 14 0
      package.json

+ 2 - 0
.gitignore

@@ -0,0 +1,2 @@
1
+node_modules
2
+package-lock.json

+ 25 - 0
client.js

@@ -0,0 +1,25 @@
1
+var diont = require('diont')({
2
+	broadcast: true
3
+});
4
+
5
+// ======
6
+// Listen for announcements and renouncements in services
7
+// ======
8
+diont.on("serviceAnnounced", function(serviceInfo) {
9
+	// A service was announced
10
+	// This function triggers for services not yet available in diont.getServiceInfos()
11
+	// serviceInfo is an Object { isOurService : Boolean, service: Object }
12
+	// service.name, service.host and service.port are always filled
13
+	console.log("A new service was announced", serviceInfo.service);
14
+	// List currently known services
15
+	console.log("All known services", diont.getServiceInfos());
16
+});
17
+
18
+diont.on("serviceRenounced", function(serviceInfo) {
19
+	// A service available in diont.getServiceInfos() was renounced
20
+	// serviceInfo is an Object { isOurService : Boolean, service: Object }
21
+	// service.name, service.host and service.port are always filled
22
+	console.log("A service was renounced", serviceInfo.service);
23
+	// List currently known services
24
+	console.log("All known services", diont.getServiceInfos());
25
+});

+ 30 - 0
index.js

@@ -0,0 +1,30 @@
1
+var diont = require('diont')();
2
+
3
+// ======
4
+// Listen for announcements and renouncements in services
5
+// ======
6
+diont.on("serviceAnnounced", function(serviceInfo) {
7
+	// A service was announced
8
+	// This function triggers for services not yet available in diont.getServiceInfos()
9
+	// serviceInfo is an Object { isOurService : Boolean, service: Object }
10
+	// service.name, service.host and service.port are always filled
11
+	console.log("A new service was announced", serviceInfo.service);
12
+	// List currently known services
13
+	console.log("All known services", diont.getServiceInfos());
14
+});
15
+
16
+diont.on("serviceRenounced", function(serviceInfo) {
17
+	console.log("A service was renounced", serviceInfo.service);
18
+	console.log("All known services", diont.getServiceInfos());
19
+});
20
+
21
+// ======
22
+// Announce our own service
23
+// ======
24
+var service = {
25
+	name: "TestServer 1",
26
+	host: "127.0.0.1", // when omitted, defaults to the local IP
27
+	port: "1231"
28
+	// any additional information is allowed and will be propagated
29
+};
30
+diont.announceService(service);

+ 14 - 0
package.json

@@ -0,0 +1,14 @@
1
+{
2
+  "name": "udp-discover-server",
3
+  "version": "1.0.0",
4
+  "description": "",
5
+  "main": "index.js",
6
+  "scripts": {
7
+    "test": "echo \"Error: no test specified\" && exit 1"
8
+  },
9
+  "author": "",
10
+  "license": "ISC",
11
+  "dependencies": {
12
+    "diont": "^0.9.7"
13
+  }
14
+}