Difference in Socket.io statement

3

I'm starting to work with Socket.io on Node.js, the question for now is simple. Using my example below. What's the difference in using socket.emit () and chat.emit ()? PS: * I hope you have no kkk syntax error.

var chat = io.of('/chat')
             .on('connection', function (socket) {
                 socket.emit('testOne', {
                    data: 'data'
                 });
                 chat.emit('testTwo', {
                    data2: 'data2'
                 });
             });
    
asked by anonymous 27.02.2016 / 14:20

1 answer

2

socket.emit will issue the event to this specific socket, in case of any client that is connected and represents the socket.

In chat.emit the event is issued to all clients that are logged in the /chat namespace (which is created in io.of('/chat') ).

    
27.02.2016 / 16:54