I'm going through the O'Reilly node - up and running book.  In chapter 2 
they have code to put together a chat server.  It's simple enough and 
though mine is somewhat working, the output doesn't match what they show. 
 In the example, it shows that when a client enters some data it's written 
to the other clients terminal window as a full string.  In my case it 
writes out each character instead of waiting until I hit the enter key. 
 From what I can see, my code is the same as the book so I'm not sure why 
the output is different.  Can anyone see the problem?   Thanks.

var net = require("net");

var chatServer = net.createServer(), clientList = [];

chatServer.on("connection", function(client){
 client.name = client.remoteAddress + ":" + client.remotePort;
 clientList.push(client);

client.write("Hi " + client.name + "!\n");
 client.on("data", function(data){
broadcast(data, client);
});
});

function broadcast(message, client){
for (var i = 0; i < clientList.length; i++){
if (client !== clientList[i]){
clientList[i].write(client.name + " says " + message); 
}
}
}

chatServer.listen(9000);

-- 
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

Reply via email to