Send response to all clients except sender

前端 未结 10 1636
囚心锁ツ
囚心锁ツ 2020-11-22 14:26

To send something to all clients, you use:

io.sockets.emit(\'response\', data);

To receive from clients, you use:

socket.on         


        
10条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 15:09

    For namespaces within rooms looping the list of clients in a room (similar to Nav's answer) is one of only two approaches I've found that will work. The other is to use exclude. E.G.

    socket.on('message',function(data) {
        io.of( 'namespace' ).in( data.roomID ).except( socket.id ).emit('message',data);
    }
    

提交回复
热议问题