質問

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