Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

89
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda