Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

224
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!