How to send a message to a specific room with Socket.io?

1

How do I send a message to a specific room? type:

server.js

io.in('roomA').on('msg', function(msg) {
...
});

client.js

io.in('roomA').emit('msg, 'Hi');
    
asked by anonymous 22.05.2016 / 03:55

1 answer

2

According to official documentation , to send a message to a specific room you can use the example below:

//enviando para todos na sala (room) 'game', com exceção do remetente
socket.to('game').emit('nice game', "let's play a game");

// enviando para todos na sala (room) 'game', incluindo o remetente
io.in('game').emit('big-announcement', 'the game will start soon');
    
03.04.2017 / 21:38