Browse Source

update name etc

ameba23 2 years ago
commit
8c945f85bc
3 changed files with 38 additions and 0 deletions
  1. 12
    0
      index.js
  2. 14
    0
      package.json
  3. 12
    0
      recieve.js

+ 12
- 0
index.js View File

@@ -0,0 +1,12 @@
1
+var createStream = require('broadcast-stream')
2
+
3
+var stream = createStream(8999)
4
+
5
+stream.on('data', function (msg) {
6
+  console.log(msg.toString())
7
+  console.log(msg.address, msg.port, msg.loopback, msg.echo)
8
+})
9
+
10
+setInterval(function () {
11
+  stream.write(Buffer.from('cobox replicator over here', 'utf8'))
12
+}, 1000)

+ 14
- 0
package.json View File

@@ -0,0 +1,14 @@
1
+{
2
+  "name": "try-udp-broardcast",
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
+    "broadcast-stream": "^0.2.2"
13
+  }
14
+}

+ 12
- 0
recieve.js View File

@@ -0,0 +1,12 @@
1
+var createStream = require('broadcast-stream')
2
+
3
+var stream = createStream(8999)
4
+
5
+stream.on('data', function (msg) {
6
+  console.log(msg.toString())
7
+  console.log(msg.address, msg.port, msg.echo)
8
+})
9
+
10
+setInterval(function () {
11
+  // stream.write(Buffer.from(new Date().toString(), 'utf8'))
12
+}, 1000)