-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
35 lines (28 loc) · 913 Bytes
/
app.js
File metadata and controls
35 lines (28 loc) · 913 Bytes
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
var WebSocketServer = require('ws').Server
, http = require('http')
, express = require('express')
, app = express()
, dgram = require('dgram');
var client = dgram.createSocket("udp4");
app.use(express.static(__dirname + '/client'));
var server = http.createServer(app);
server.listen(8080, '0.0.0.0');
var wss = new WebSocketServer({server: server});
wss.on('connection', function(ws) {
var msgConnect = new Buffer([0]);
client.send(msgConnect, 0, msgConnect.length, 44400, '10.8.11.91', function(err, bytes) {
console.log('connect sent');
});
ws.on('message', function (message) {
var msg = new Buffer([message[0]]);
client.send(msg, 0, 1, 44400, '10.8.11.91', function(err, bytes) {
console.log(msg);
});
});
client.on("message", function (msg, rinfo) {
console.log('msg');
console.log(msg);
console.log('rinfo');
console.log(rinfo);
});
});