-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
55 lines (48 loc) · 1.46 KB
/
index.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
var express = require("express");
var http = require('http').Server(express);
var io = require('socket.io')(http);
var net = require('net');
var app = express();
var p = 0;
var q = 0;
/* serves main page */
app.get("/", function(req, res) {
p = req.query.p;
q = req.query.q;
console.log(req.query.q + " " + req.query.p);
// client.write('Hello');
//io.emit('data', 'res');
//console.log("passed");
res.sendfile('new.html')
});
app.post("/user/add", function(req, res) {
/* some server side logic */
// res.send("OK");
console.log(req.body);
});
app.get("/datafeed",function(req, res) {
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify({ well: q, tank: p }));
});
io.on('connection', function(socket){
console.log('User connected');
socket.on('message', function(msg){
console.log('message: ' + msg);
// client.write('Hello');
});
});
/* serves all the static files */
// app.get(/^(.+)$/, function(req, res){
// console.log('static file request : ' + req.params);=
// res.sendfile( __dirname + req.params[0]);
// console.log(req);
// });
var port = process.env.PORT || 5000;
app.listen(port, function() {
console.log("Listening on " + port);
});
// var client = new net.Socket();
// client.connect(5000, '127.0.0.1', function() {
// console.log('Connected');
// // client.write('Hello, server! Love, Client.\n');
// });