Grizzly Comet 仅向一个客户端推送
我想知道是否可以通过 Comet 将一些 dama 推送到仅一个客户端(连接更多客户端)。
假设我有 400 个客户端连接到服务器,其中只有 20 个需要获取刷新命令。我怎样才能只向这 20 个客户端发送这个命令(我在服务器端有他们的 IP,所以我知道他们是哪一个)。
这可能吗?如果可能的话——如何实现?
I would like to know, if it is possible to push some dama via Comet to only one client (more clients connected).
Let's say I have 400 clients connected to server and only 20 of them needs to get refresh command. How can I send this command only to those 20 clients (I have their IPs on server side, so I know which one they are).
Is this possible and if yes - how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您调用 context.notify() 时,您可以传入一个对象,该对象包含要发送的有效负载以及应该获取该有效负载的 IP 列表。然后在 CometHandler 中,您可以简单地根据该列表检查请求远程/客户端 IP。如果列表为空或包含该处理程序的 IP,则发送它。否则,忽略它。当您创建处理程序时,您需要传入或附加必要的信息来进行检查,但这也是一件非常简单的事情。
When you call context.notify(), you can pass in an object that contains both the payload you want to send out and the list of IPs that should get it. Then in your CometHandler, you can simply check the requests remote/client IP against that list. If the list is empty or contains the IP for that handler, send it. Otherwise, ignore it. When you create your handler you'll want to pass in or attach the necessary info to do that check but that's a pretty simple affair, too.