-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
41 lines (32 loc) · 912 Bytes
/
app.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
var net = require('net');
var http = require('http');
var io = require('socket.io').listen(5000);
var gsock;
var server = net.createServer(function (socket) {
console.log("processing connected");
socket.pipe(socket);
gsock = socket;
var message = "";
socket.on("data", function(chunk) {
message += chunk;
var newlineIndex = message.indexOf('\n');
if (newlineIndex !== -1) {
var json = message.slice(0, newlineIndex);
gsock.emit("json", json);
message = message.slice(newlineIndex + 1);
}
});
gsock.on("json", function(data) {
try {
json = JSON.parse(data);
io.sockets.emit('kinect', json);
} catch (Err) {
console.log("skipping: " + Err);
return; // continue
}
});
});
server.listen(1337, "127.0.0.1");
io.sockets.on('connection', function (socket) {
console.log("browser connected");
});