Socket.io rooms is not getting message

The socket.io connection made by second.pug never receives a message because your server never sends it a message.

Here’s what first.pug does:

  1. It creates a socket.io connection to your server.
  2. When that connection succeeds, it sends a join123 message to that server.

Here’s what your socket.io server does:

  1. It listens for connecting clients.
  2. When a client connects, it puts that client into the join123 room.
  3. No messages are sent out to any of the connected clients.

Note: there is no listener on the server for the join123 message that the client sent so likely something is wrong there.

Here’s what second.pug does:

  1. It create a socket.io connection to your server.
  2. It listens for a join123 message to be sent to it.

But, nothing ever sends a join123 message to second.pug, so second.pug never receives that message. first.pug sends a join123 message to your server, but the server never sends that to anyone else. The act of doing socket.join('join123') does not cause any messages to be sent. It just adds the socket to a room by that name. If you want the second.pug to get a join123 message, you would have to write code on your server that actually sends that message either to all connections or somehow just to the second.pug connection.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top