forked from veer66/switch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
39 lines (30 loc) · 849 Bytes
/
Copy pathserver.js
File metadata and controls
39 lines (30 loc) · 849 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
36
37
var express = require('express'),
nunjucks = require("nunjucks"),
net = require("net");
var app = express();
var status = "on";
var v = "N/A";
nunjucks.configure(__dirname + '/views', {
autoescape: true,
express: app
});
app.get('/', function(req, res) {
if (req.query.status) {
status = req.query.status;
}
res.render('index.html', {status:req.query.status, v:v});
});
var httpServer = app.listen(3000, function() {
var host = httpServer.address().address;
var port = httpServer.address().port;
console.log('The app listening at http://%s:%s', host, port);
});
var tcpServer = net.createServer();
tcpServer.listen(6981, '0.0.0.0');
console.log("TCP server is running ...");
tcpServer.on('connection', function(sock) {
sock.on('data', function(buf) {
v = buf.toString();
sock.write(status);
});
});