Question

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?

Était-ce utile?

La solution

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);
});
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top