如何使用订阅模式“两者”添加名册
我正在使用 smack 3.1.0,当我添加名册时,我无法获得“两者”订阅。谁能帮助我? 下面是我的代码:
Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.accept_all);
Roster roster = connection.getRoster();
roster.createEntry("[email protected]","me",null)
代码执行后,我在 openfire 中观察到订阅是“to”
i'm using smack 3.1.0, and when i add a roster,i can't get subscription "both". who can help me?
below is my code:
Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.accept_all);
Roster roster = connection.getRoster();
roster.createEntry("[email protected]","me",null)
after the code execution, i observed in openfire the subscription is "to"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
重写 @mschonaker 的答案,使其更清晰一些。
两个用户都需要相互订阅并接受他们收到的订阅请求。我们称他们为爱丽丝和鲍勃。 Alice 向 Bob 发送订阅请求:
当 Bob 收到该请求时,他批准该请求:
Bob 可能也对 Alice 的存在感兴趣,因此他订阅了她:
并且 Alice 需要批准 Bob 的请求:
RFC6121 的第 3.1 节 是当前有关其工作原理的最佳参考。
Rewriting @mschonaker's answer to be a little more clear.
Both users need to subscribe to each other and accept the subscription request they received. Let's call them Alice and Bob. Alice sends a subscription request to Bob:
When Bob receives the request, he approves it:
Bob may also be interested in Alice's presence, so he subscribes to her:
And Alice needs to approve Bob's request:
Section 3.1 of RFC6121 is the current best reference for how this works.
两个用户都需要互相订阅。通过发送存在订阅节。在 Smack 中:
RFC6121 的第 3.1 节将为您提供语义详细信息。
Both users need to subscribe to each other. By sending a presence subscription stanza. In Smack:
Section 3.1 of the RFC6121 will give you the semantic details.
好吧,我努力了几天,终于把事情搞定了。谢谢@Joe Hildebrand,你的回答让我走上了解决这个问题的正确道路。我已经用手动订阅模式实现了它(即用户需要手动接受另一个用户的请求)。
如果用户尚未发送订阅或取消订阅,服务器将继续向用户推送订阅请求(重新登录时)。因此,您可以做的是将传入的订阅请求本地保存在列表中,并将其显示为“好友请求列表”以供手动接受/拒绝。如果您的应用程序重新启动(并因此重新连接到服务器),服务器将再次推送订阅请求。
其工作原理如下:
User1 检查 User2 是否在 User1 的名册中。 User2 位于 User1 的名册中。用户1向用户2发回订阅状态(用户2>用户1订阅完成)。
Okay, I toiled hard at this for a couple of days and finally got things working. Thank you @Joe Hildebrand, your answer put me on the right track to solve this. I have implemented it with a manual subscription mode (ie. user needs to accept another user's request manually).
The server keeps pushing subscribe request to the user (upon re-login) if the user hasn't sent a subscribed or unsubscribed back. So what you can do is save the incoming subscribe requests locally in a list and display that as a "friend request list" for manual accept/reject. If your application gets restarted (and hence re-connects to server), the server will push subscribe requests again.
This is how it works:
User1 checks if User2 is in User1's roster. User2 is in User1's roster. User1 sends back a subscribed presence to User2 (User2 > User1 subscription complete).
如果您使用的是 open fire 服务器,您还可以使用 用户服务插件 这将创建具有订阅的名册...
If you are using open fire server you can also use User Service plugin which will create roster with subscription both...
我遇到了同样的问题,但我得到了解决方案,如何订阅设置“两者”,
下面是向用户发送订阅,当您添加用户
和接收端放在连接类中的方法下方时,并且 PresenceChanged 是 RosterListener 的默认方法。
Same problem I was face but I got the solution how subscribe set 'both'
Below is sending subscription to user, when you added the user
and Receiving end put below method in connection class and presenceChanged is default method of RosterListener.