문제

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

Hello, this emits to all the sockets, but each socket gets the same data, is it possible for me to emit to them all, but give each of them different data?

도움이 되었습니까?

해결책

As far as I know this is not possible. It will depend on what you want to do really (and how). First thing that came to my mind as a alternative is identifying your users by socket.id and then send them the data accordingly.

Example:

io.sockets.clients().forEach(function (socket) {
    if(socket.id == 1337) data = {test: "test1"};
    if(socket.id == 404) data = {test: "test2"};

    socket.emit('data',data);
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top