如何在不轮询的情况下向客户端发送消息?

发布于 2024-09-26 02:06:34 字数 100 浏览 7 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

白鸥掠海 2024-10-03 02:06:34

如果您谈论的是 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.

空气里的味道 2024-10-03 02:06:34

您可能已经看过一些聊天室示例...

因为您只想向数据存储区上的用户发送消息(提示:IMProperty 非常适合存储此类数据),只需直接发送消息即可:

from google.appengine.api import xmpp
# `destination` is a list of JIDS
# `message` is a normal unicode string
xmpp.send_message(destination, message)

您可以找到 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:

from google.appengine.api import xmpp
# `destination` is a list of JIDS
# `message` is a normal unicode string
xmpp.send_message(destination, message)

You can find a great tutorial on using XMPP by Nick Johnson here

可是我不能没有你 2024-10-03 02:06:34

请注意,您现在可以使用 App Engine Channel API 来执行此操作:http://code。 google.com/appengine/docs/python/channel/

您可以使用以下方法为给定客户端创建通道:

channel.create_channel(client_id)

然后,当您想要更新该客户端时,发送一条消息:

channel.send_message(client_id, message)

基本上每个客户端都会获得一个持久连接,您可以使用可以推送消息过来。

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:

channel.create_channel(client_id)

Then when you want to update that client, send a message:

channel.send_message(client_id, message)

Basically each client will get a persistent connection that you can push messages over.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文