you are correct, removing broadcast works. a not so related question, in the browser side, I'd like to display only 10 of the lines, if more than that, it scrolls up, what's a good approach to this? thanks.
On Saturday, November 10, 2012 5:14:51 PM UTC+8, Cryptic Swarm wrote: > > You are starting a new process for every connection. > You are using the broadcast flag in socket.io. > > """ Quoted from http://socket.io/#how-to-use > Broadcasting means sending a message to everyone else except for the > socket that starts it. > """ > > In your case you would likely have the messages show up N-1 times (where N > is the number of clients connected). If you only had one client connect > you would see the messages 0 times. > > On Sat, Nov 10, 2012 at 2:03 AM, Angelo Chen <[email protected]<javascript:> > > wrote: > >> Hi, >> >> I was trying to tail a log and send the out put to a connected >> browser, i can see the log data in the part of: >> tail_child.stdout.on('data', function (data) from console.log, but >> the socket.broadcast.emit seems not sending out any data, any way to >> make this work? thanks, Angelo >> >> part of app.js >> >> socketio.listen(server).on('connection', function (socket) { >> console.log("new socket") >> >> // everytime there is a new request, spawn an child process >> var tail_child = spawn('tail', ['-f', '/var/log/system.log']); >> >> tail_child.stdout.on('data', function (data) { >> // write it on the console >> console.log(data.toString()); // yes, i can see the data here >> // send it to the browser because the browser will be waiting >> for the next chunk of data >> socket.broadcast.emit('message', data.toString()); // no, >> browser can not see any >> }); >> >> socket.on('disconnect', function () { >> tail_child.kill(); >> console.log('disconnected me') >> }); >> }); >> index.html >> >> <html> >> >> <head> >> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/ >> jquery.min.js"></script> >> <script src="/socket.io/socket.io.js"></script> >> <script> >> $(function () { >> var iosocket = io.connect(); >> >> iosocket.on('connect', function () { >> $('#incomingChatMessages').append($ >> ('<li>Connected</li>')); >> >> iosocket.on('message', function (message) { >> $('#incomingChatMessages').append($('<li></ >> li>').text(message)); >> }); >> iosocket.on('disconnect', function () { >> $ >> ('#incomingChatMessages').append('<li>Disconnected</li>'); >> }); >> }); >> >> $('#outgoingChatMessage').keypress(function (event) { >> if (event.which == 13) { >> event.preventDefault(); >> iosocket.send($ >> ('#outgoingChatMessage').val()); >> $('#incomingChatMessages').append($('<li></ >> li>').text($('#outgoingChatMessage').val())); >> $('#outgoingChatMessage').val(''); >> } >> }); >> }); >> </script> >> </head> >> >> <body>Incoming Chat: >> <ul id="incomingChatMessages"></ul> >> <br /> >> <input type="text" id="outgoingChatMessage"> >> </body> >> >> </html> >> >> -- >> Job Board: http://jobs.nodejs.org/ >> Posting guidelines: >> 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 post to this group, send email to [email protected]<javascript:> >> To unsubscribe from this group, send email to >> [email protected] <javascript:> >> For more options, visit this group at >> http://groups.google.com/group/nodejs?hl=en?hl=en >> > > -- Job Board: http://jobs.nodejs.org/ Posting guidelines: 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 post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en
