Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add roster with subscription mode "both"

Tags:

java

xmpp

smack

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"

like image 578
snowway Avatar asked Apr 27 '11 10:04

snowway


2 Answers

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:

Presence subscribe = new Presence(Presence.Type.subscribe);
subscribe.setTo('[email protected]');
connection.sendPacket(subscribe);

When Bob receives the request, he approves it:

Presence subscribed = new Presence(Presence.Type.subscribed);
subscribed.setTo('[email protected]');
connection.sendPacket(subscribed);

Bob may also be interested in Alice's presence, so he subscribes to her:

Presence subscribe = new Presence(Presence.Type.subscribe);
subscribe.setTo('[email protected]');
connection.sendPacket(subscribe);

And Alice needs to approve Bob's request:

Presence subscribed = new Presence(Presence.Type.subscribed);
subscribed.setTo('[email protected]');
connection.sendPacket(subscribed);

Section 3.1 of RFC6121 is the current best reference for how this works.

like image 166
Joe Hildebrand Avatar answered Sep 30 '22 19:09

Joe Hildebrand


Both users need to subscribe to each other. By sending a presence subscription stanza. In Smack:

    Presence presence = new Presence(Presence.Type.subscribe);
    presence.setTo(jid);
    connection.sendPacket(presence);

Section 3.1 of the RFC6121 will give you the semantic details.

like image 26
Martín Schonaker Avatar answered Sep 30 '22 20:09

Martín Schonaker