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

228
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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