-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogserver.js
64 lines (43 loc) · 1.15 KB
/
logserver.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
56
57
58
59
60
61
62
63
64
/*
*
* Author: Sherwin R. Terunez
* Contact: sherwinterunez@yahoo.com
*
* Description:
*
* NodeJS Log Server
*
* December 7, 2016
*
*/
// log server
const TIMEOUT = 1000;
const PORT = 8090;
const ADDRESS = '0.0.0.0';
var PHPFPM = require('./node_modules/node-phpfpm');
var io = require('./node_modules/socket.io');
var spawn = require('child_process').spawn;
var http = require('http');
var server = http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('end.\n');
});
server.listen(PORT, ADDRESS, function () {
console.log('Server running at http://%s:%d/', ADDRESS, PORT);
console.log('Press CTRL+C to exit');
});
var io = io.listen(server);
io.on('connection', function(client){
console.log(client);
client.on('call', function(msg, fn) {
client.myfilename = msg;
console.log('call',msg);
fn(0,'sherwin!');
var tail = spawn("tail", ["-f", client.myfilename]);
client.send( { filename : client.myfilename } );
tail.stdout.on("data", function (data) {
//console.log(data.toString('utf-8'))
client.send( { tail : data.toString('utf-8') } )
});
});
});