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

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

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 Denunciar

0

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

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