当前位置: 动力学知识库 > 问答 > 编程问答 >

Socket.io - Only Emit to Certain Users?

问题描述:

Forewarning, I am very new to Node.js and Socket.io and this probably has a simple answer.

I am using it in conjunction with a PHP app. The intention is to have real-time notifications.

If you take a scenario such as Facebook -- something with lots of users, but the notifications should only be sent out to certain sets of users, how do I target those users?

I've thought of setting something like:

socket.on('notification-[user_id]', function() {...} );

But that would be insane considering thousands of users.

It also seems to be insane to send notifications to thousands of users and have each user have to figure out whether it's for them or not.

Is there a way around this? What am I missing?

网友答案:

I'm new to them too, but i think you can do it like this: In the client side you can just:

socket.on('notification',function(){...});

In the server side you can use :

io.sockets.connected[socketid].emit('nofification',data);

Hope it can help you~

分享给朋友:
您可能感兴趣的文章:
随机阅读: