判断XMPP用户是否在线

发布于 2024-09-19 22:40:17 字数 255 浏览 8 评论 0原文

我正在使用 xmpppy 库编写一个可以与用户聊天的 XMPP 客户端。它有自己的 XMPP 用户帐户,需要知道给定用户是否在线。然而,关于如何执行此操作的文档有点稀疏。你会推荐什么?

到目前为止,我见过的唯一解决方案是在 XMPP 服务器启动之前启动一个守护进程,并监视发送出去的所有状态消息 - 然后,如果用户发送了“我在线”,则称他们在线- 键入消息,但不是相应的“我正在注销”消息。然而,作为 XMPP 的新手,我认为会有更好的方法来做到这一点。

I'm using the xmpppy library to write an XMPP client that can chat with users. It has its own XMPP user account and needs to know if a given user is online. However, the documentation is a bit sparse on how to do this. What would you recommend?

The only solution I've seen thus far is to start up a daemon before the XMPP server starts and monitor all presence messages that are sent out - then a user is said to be online if they've sent the "I'm online"-type message but not the corresponding "I'm logging off" message. However, being new to XMPP in general, I would think there would be a nicer way to do this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

审判长 2024-09-26 22:40:17

简单的方法是支持“订阅”在线状态消息——这可以让其他用户通过“订阅”尝试来检查您当前是否在线(如果他们还不知道)。查看这个有用的指南开始使用,并且许多更重要细节的标准(特别是保护您的隐私,如果需要,免受您不同意的用户的订阅请求)不知道)。

The simple way is to support "subscribe" presence message -- this lets another user check if you're currently present (if they don't already know) by a "subscribe" attempt. Check this useful guide to get started, and the standard for many more important details (esp. on protecting your privacy, if needed, from subscribe requests from user you don't know).

半步萧音过轻尘 2024-09-26 22:40:17

基本上有三种方式连接到 XMPP 服务器:作为客户端(您已经完成)、作为组件和作为另一个服务器。服务器到服务器类型 (s2s) 只是一种联合连接,非常类似于邮件服务器相互交换电子邮件的方式。

亚历克斯描述了客户如何跟踪状态。 XMPP 要求我批准您可以接收我的状态信息,反之亦然。对于您的机器人来说,这意味着您需要跟踪谁在线,最终用户需要接受您的在线请求。这还意味着您可以响应用户的在线请求,并让他们了解您的机器人是否已启动。

最后一种方法是作为受信任的组件,并且仅在您运行服务器时才有效。即,如果您尝试在 jabber.org 服务器上执行此操作,那么您就不走运了,因为您没有运行该服务器。好处是您可以访问 XMPP 服务器的内部结构,例如拉取所有在线用户的列表。缺点是您的组件/机器人实现对于每个服务器实现来说都是不同的。

There are basically three ways to connect to an XMPP server: as a client (which you've done), as a component, and as another server. The server-to-server type (s2s) is just a federated connection, very much like how mail servers exchange email with each other.

Alex described how clients keep track of presence. XMPP requires me to approve that you can receive my presence information and vice versa. For your bot this means for you to keep track of who's online the end users need to accept your presence requests. It also means that you can respond to the user's presence requests and keep them informed about if your bot is up or not.

The last way is as a trusted component, and only works if you're running the server. i.e. if you're trying to do this on the jabber.org server, you're out of luck, because you're not running that server. The upsdie is you can have access to the internals of the XMPP server, like pulling lists of everyone who's online. The downside is your component / bot implementation is going to be different for every server implementation.

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