Guest User

Untitled

a guest
Jan 18th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. // sending to sender-client only
  2. socket.emit('message', "this is a test");
  3. // sending to all clients, include sender
  4. io.emit('message', "this is a test");
  5. // sending to all clients except sender
  6. socket.broadcast.emit('message', "this is a test");
  7. // sending to all clients in 'game' room(channel) except sender
  8. socket.broadcast.to('game').emit('message', 'nice game');
  9. // sending to all clients in 'game' room(channel), include sender
  10. io.in('game').emit('message', 'cool game');
  11. // sending to sender client, only if they are in 'game' room(channel)
  12. socket.to('game').emit('message', 'enjoy the game');
  13. // sending to all clients in namespace 'myNamespace', include sender
  14. io.of('myNamespace').emit('message', 'gg');
  15. // sending to individual socketid
  16. socket.broadcast.to(socketid).emit('message', 'for your eyes only');
Add Comment
Please, Sign In to add comment