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

198
Views
socket.io emitting to all clients works, but emitting to room doesn't work

When I try io.emit(), the message gets emitted to everyone but when I try io.to(room).emit(), the message doesn't get emitted (In the 3rd last line of the code).

I manually checked the sockets in the room, and all are present in the room correctly. But the message never gets transmitted.

io.on('connection', (socket) => {
    socket.on("create game", async ( gameID, host ) => {
        socket.join(gameID);
        // some logic
    })
    socket.on("join game", async ( gameID, user ) => {
        socket.join(gameID);
        // some logic
        io.to(gameID).emit("new user", user);
    })
});
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Is your socket connected to a particular namespace? In my project I had on the client side the following:

const socket = io.connect("/play-online").

So in order to emit to the room I created for that, I had to do:

io.of("/play-online").to(room.roomName).emit("move", move);
about 4 years ago · Juan Pablo Isaza Report

0

I was able to fix it using socket.in(gameID).emit("new user", user); instead

about 4 years ago · Juan Pablo Isaza 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!