In the server every time a new socket connection is made you are creating a
new Tail instance and then using io.sockets.emit() which sends a message to
all connected clients, hence the behavior you are seeing. If you really
just want to globally tail and emit events move that handle outside of the
connection handler. If each connection is going to specify which file it
wants to tail then you'll want to just emit on that connection not all
connections or if you expect multiple clients to want to all tail the same
file look into socket.io's room feature to only create each tail handler
once. Lastly as written I don't see that the tail instances are being
stopped and cleaned up when the client disconnects.

-- Daniel R. <[email protected]> [http://danielr.neophi.com/]


On Wed, May 7, 2014 at 9:54 PM, vqck <[email protected]> wrote:

> 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);
>              });
>          },
>
> --
> Job board: http://jobs.nodejs.org/
> New group rules:
> https://gist.github.com/othiym23/9886289#file-moderation-policy-md
> Old group rules:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> ---
> You received this message because you are subscribed to the Google Groups
> "nodejs" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/nodejs/5bf22709-9846-4cb9-bb10-04e79512bb96%40googlegroups.com<https://groups.google.com/d/msgid/nodejs/5bf22709-9846-4cb9-bb10-04e79512bb96%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/CAETDeSD%3DTT8NCYaqC3_ipKX8dVPz6h2JJvcSvFQ9u4biDdU1Pw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to