Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

87
Views
Handling multiple data events in Node.js

I think have a misunderstanding of how TCP sockets work in Node!

My server is receiving data from a client, processing the data, and sending a response. However, while processing the response, another 'data' event fires .... which I wasn't really expecting - I figured that the first handler would complete, before further events trigger. Probably a bad assumption on my part, but I can't find much documentation that shows examples other than very trivial ones.

Are there any elegant solutions to this problem? I will probably have to perhaps use a separate loop that polls for data being available in a FIFO type Buffer, I prefer an event based mechanism, but perhaps I can't in this case.

// Accept a connection from a client ... 
_server.on('connection', async function(socket){

  // Some new data has arrived - this can fire while
  // still processing the previous event
  socket.on('data', async function(data){
    
     // Process the data ... DB updates etc. 

  });
});
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!