如何在不轮询的情况下向客户端发送消息?
GAE 聊天的每个示例都使用某种轮询。但是,如果我的 GAE 应用程序包含客户端列表(如有必要,在数据存储中),也许我可以通过向所有这些客户端发送消息来避免轮询。我怎样才能实现这个目标?
Every example for GAE Chats uses some kind of polling. However, if my GAE app holds a list of clients (in the datastore if necessary), perhaps I could avoid polling by sending a message to all these clients. How can I achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您谈论的是 HTTP,简短的回答是 GAE 目前不支持它。我认为您所问的有时称为 BOSH。一旦 WebSockets 变得更加普遍,它们将是解决这个问题的绝佳解决方案。
同时,您可能需要查看 XMPP。使用 XMPP 您可以避免轮询。 Google 发布了Channel API(尚未发布),这基本上将为您提供与 websocket 相同的功能。
If you are talking about HTTP, the short answer is that GAE does not currently support it. What I think you are asking about is sometimes called BOSH. Once WebSockets become more widespread, they will be an excellent solution for this problem.
In the mean time you might want to look at XMPP. Using XMPP you can avoid polling. Google has announced a Channel API (yet to be released) which will basically give you the same features as websockets.
您可能已经看过一些聊天室示例...
因为您只想向数据存储区上的用户发送消息(提示:IMProperty 非常适合存储此类数据),只需直接发送消息即可:
您可以找到 Nick Johnson 撰写的关于使用 XMPP 的精彩教程< a href="http://code.google.com/appengine/articles/using_xmpp.html" rel="nofollow">此处
You've probably seen some chat room examples...
Since you just want to send a message to users on your datastore (Tip: the IMProperty is great to store such data), it's just a matter of directly sending the message:
You can find a great tutorial on using XMPP by Nick Johnson here
请注意,您现在可以使用 App Engine Channel API 来执行此操作:http://code。 google.com/appengine/docs/python/channel/
您可以使用以下方法为给定客户端创建通道:
然后,当您想要更新该客户端时,发送一条消息:
基本上每个客户端都会获得一个持久连接,您可以使用可以推送消息过来。
Note that you can now use the App Engine Channel API for this: http://code.google.com/appengine/docs/python/channel/
You can create a channel for a given client using:
Then when you want to update that client, send a message:
Basically each client will get a persistent connection that you can push messages over.