1

I want to implement Socket.io's Room functionality and my configuration is like this:

io.on('connection', function (socket) {
    socket.join('123');
    //...
}

And when I want to emit an event:

socket.in('123').emit('sendMessage', {items:values]});

But everyone gets this message except the sender of this message. Why? Do I have to emit() a separate message for sender?

If I use socket.to('123') instead of socket.in('123') I get the same result and nothing changes. I use the Socket.io's official documents: http://socket.io/docs/rooms-and-namespaces/

Adam Boduch
  • 11,023
  • 3
  • 30
  • 38
Fcoder
  • 9,066
  • 17
  • 63
  • 100
  • Here you have a [list](http://stackoverflow.com/questions/10058226/send-response-to-all-clients-except-sender-socket-io) with the different methods. Try with `io.sockets.in('123').emit('sendMessage', 'your message');` – gastonmancini Jul 10 '15 at 17:16

1 Answers1

1

To get this to send to everyone including the sender you need to use the following syntax:

io.sockets.in('123').emit('message', 'cool game');

note that this is using the global io which I would assume you would have included like this:

var io = require('socket.io');
real_ate
  • 10,861
  • 3
  • 27
  • 48