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

227
Visualizações
Flask-socketIO is not sending emit() to client

I am struggling with issue, my emit() function is not sending anything to frontend, despite that its receiving data. Here is my code:

Flask backend:

def ack():
   print("message was received!")

@socketio.on("add_to_chat_event")
def handle_event(data):
  print(data)
  emit("my response", data, callback=ack, broadcast=True)

And here is my frontend:

function appendToChat(room, username) {
    socket.emit("add_to_chat_event", { room: room, username: username });
  }

  $(".room").click(function () {
    choiced_room = this.getAttribute("value");
    socket = io();
    socket.on("connect", function () {
      joinRoom(choiced_room, username);
      appendToChat(choiced_room, username);
    });
    socket.on("message", function (data) {
      $("#messages").append(`<li class ='list-group'>${data}</li>`);
      $("#Messages").value = "";
    });

    socket.on("add_to_chat_event", function (data) {
      console.log(data, "tutaj");
      if (!data) {
        $(".users").append(`<li>Anonymous</li>`);
      } else {
        $(".users").append(`<li>${data}</li>`);
      }
    });
  });

The problem is in the emit function becasue when I am printing received data its all fine. Am I missing something ? Thanks for the answer.

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

Problem is already solved, this is not mentioned in documentation. First parameter of emit() method is an listener for the frontend. In my situation i had to add to emit() method "add_to_chat_event" as first parameter instead of 'my response'

about 4 years ago · Santiago Gelvez Relatório
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