-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtuio-server.js
32 lines (25 loc) · 967 Bytes
/
tuio-server.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
// > node server.js 8888
var port = 8080;
if (process.argv.length > 2) port = parseInt(process.argv[2]);
const dServer = require('dgram').createSocket('udp4');
const express = require('express');
const app = express();
const http = require('http');
const WebSocket = require('ws');
const server = http.createServer(app);
const wss = new WebSocket.Server({ server });
// bind UDP datagram server to standard TUIO port
dServer.bind(3333, '0.0.0.0');
wss.on('connection', function(ws) {
console.log('Connected to WebSocket Server');
// forward UDP packets via WebSockets
dServer.on('message', function(buf, rinfo){
ws.send(buf);
});
dServer.on('listening', function() {
const address = server.address();
console.log(`UDP Server listening ${address.address}:${address.port}`);
});
});
app.use(express.static('./')); //Tells the app to serve static files from ./
server.listen(port, () => console.log('Web Server listening on port '+port));