I have a socket server in Node.js and I’d like to be able to read from stdin at the same time the server is listening. It works only partially. I’m using this code:
process.stdin.on('data', function(chunk) {
for(var i = 0; i < streams.length; i++) {
// code that sends the data of stdin to all clients
}
});
// ...
// (Listening code which responds to messages from clients)
When I don’t type anything, the server responds to messages of the clients, but when I start typing something, it isn’t until I press Enter that it continues with this task. In the time between starting to type something and pressing Enter, the listening code seems to be suspended.
How can I make the server still respond to clients while I’m typing in stdin?
I just wrote a quick test and had no problems processing input from stdin and http server requests at the same time, so you’ll need to provide detailed example code before I can help you. Here’s the test code which runs under node 0.4.7: