Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5933675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:00:24+00:00 2026-05-22T15:00:24+00:00

I have a socket server in Node.js and I’d like to be able to

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:00:25+00:00Added an answer on May 22, 2026 at 3:00 pm

    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:

    var util=require('util'),
        http=require('http'),
        stdin=process.stdin;
    
    // handle input from stdin
    stdin.resume(); // see http://nodejs.org/docs/v0.4.7/api/process.html#process.stdin
    stdin.on('data',function(chunk){ // called on each line of input
      var line=chunk.toString().replace(/\n/,'\\n');
      console.log('stdin:received line:'+line);
    }).on('end',function(){ // called when stdin closes (via ^D)
      console.log('stdin:closed');
    });
    
    // handle http requests
    http.createServer(function(req,res){
      console.log('server:received request');
      res.writeHead(200,{'Content-Type':'text/plain'});
      res.end('success\n');
      console.log('server:sent result');
    }).listen(20101);
    
    // send send http requests
    var millis=500; // every half second
    setInterval(function(){
      console.log('client:sending request');
      var client=http.get({host:'localhost',port:20101,path:'/'},function(res){
        var content='';
        console.log('client:received result - status('+res.statusCode+')');
        res.on('data',function(chunk){
          var str=chunk.toString().replace(/\n/,'\\n');
          console.log('client:received chunk:'+str);
          content+=str;
        });
        res.on('end',function(){
          console.log('client:received result:'+content);
          content='';
        });
      });
    },millis);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have a simple socket server on an android emulator. When I'm only
I have a Node.js-Server with a socket.io-connection to a browser-client. sometimes the connection gets
Okay, I have a simple test server set up using socket.io in node.js. My
I have socket program which sends a file from socket client to socket server
I have a basic socket server that looks like this: IPEndPoint localEndPoint = new
I am using a node.js server to create a 'close to real-time' socket between
I have a socket.io server using redis called server.js that fires up a node
I have created a small server for communication using node.js and socket io Server:
Here's my problem: I have server A, running node.js and using socket.io for communicating
I have to create an sample code that connect to a socket server, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.