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

156
Visualizações
JS socket.io client doesn't catch an emitted event

I'm using a Python based socketio server and JS socketio client. The workflow looks roughly like this: client emits <<action1>> -> server receives <<action1>> -> server performs some calculations -> server emits <<action2>> -> client receives <<action2>> It should work in a loop.

The problem is that for some reason the last step isn't performed, client doesn't seem to catch action2 event. I can see that it has been fired from the server logs, they state that: emitting event "action2" to all [/]

Server:

@sio.on('action1')
def handle_analysis():
    ... some calculations ...
    sio.emit('action2')

Client:

import { io } from "socket.io-client";

export const socket = io("http://localhost:5550",
{
  timeout: 200000
});

  async runCalculations() {
    console.log('progress1');
    let stdoutChunks: string = '';

    const getCalculations = () => {
      socket.emit('action1');   
      return new Promise((resolve, reject) => {
          socket.on('action2', (msg) => {
            stdoutChunks += msg;
            resolve(stdoutChunks);
        })
      });
    };
    await getCalculations()
    console.log('progress2');
    return {};
  }

progress2 is never logged, because js keeps on awaiting the getCalculations function. Can anyone point where the issue might be? Each calculation takes roughly 50 seconds, I wonder if that might be the cause. I used same approach for different events that take much less time and it works perfectly, server communicates with the client without problems.

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