Hi,
I tail a log file on server and dipslay the log lines on the browser. The problem is: Every time I refresh my browser, I get one more duplicate log line. For example, on initial load, I get one log line on the browser for every line in the log file. If I refresh the browser, I get 2 line on the browser for every line in the log file. If I refresh again, I get 3 lines on the browser for every line in the log file. I have been looking at this for days now. Please help.
Here is my server code:
//Routing
app.get('/', function (req, res) {
res.redirect('/index.html');
});
server = http.createServer(app).listen(app.get('port'), function() {
console.log('Express server listening on port ' + app.get('port'));
});
socketio = require('
socket.io')
io = socketio.listen(server)
logFile = "test.log";
io.sockets.on('connection', function(socket) {
Tail = require('tail').Tail
tail = new Tail(logFile);
tail.on('line', function(data){
return io.sockets.emit('new-data', {channel: "stdout", value: data, logFile: logFile });
});
});
Here is my client code:
wireSocketIo: function() {
var logPanel = Ext.ComponentQuery.query("#logPanel")[0];
var socket = io.connect('http://localhost:3000');
socket.on('new-data', function(data) {
var newLogLine = Ext.create("Ext.Component", {html: "<div>" + data.value + "</div>"});
logPanel.add(newLogLine);
});
},