Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

88
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda