如何在订阅模式下添加名册“两者” [英] how to add roster with subscription mode "both"
问题描述
我正在使用smack 3.1.0,当我添加一个名单时,我无法获得两者订阅。谁能帮我?
以下是我的代码:
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("buddy@test.com","me",null)
代码执行后,我在openfire中观察到订阅是to
after the code execution, i observed in openfire the subscription is "to"
推荐答案
重写@mschonaker的答案要多一点明确。
Rewriting @mschonaker's answer to be a little more clear.
两位用户都需要相互订阅和接受他们收到的订阅请求。我们称他们为爱丽丝和鲍勃。 Alice向Bob发送订阅请求:
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:
Presence subscribe = new Presence(Presence.Type.subscribe);
subscribe.setTo('bob@example.com');
connection.sendPacket(subscribe);
当Bob收到请求时,他批准了该请求:
When Bob receives the request, he approves it:
Presence subscribed = new Presence(Presence.Type.subscribed);
subscribed.setTo('alice@example.com');
connection.sendPacket(subscribed);
Bob也可能对Alice的存在感兴趣,所以他订阅了她:
Bob may also be interested in Alice's presence, so he subscribes to her:
Presence subscribe = new Presence(Presence.Type.subscribe);
subscribe.setTo('alice@example.com');
connection.sendPacket(subscribe);
Alice需要批准Bob的请求:
And Alice needs to approve Bob's request:
Presence subscribed = new Presence(Presence.Type.subscribed);
subscribed.setTo('bob@example.com');
connection.sendPacket(subscribed);
RFC6121的第3.1节是目前最佳参考方式。
Section 3.1 of RFC6121 is the current best reference for how this works.
这篇关于如何在订阅模式下添加名册“两者”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!