重写@mschonaker的答案更清晰一些。
两个用户都需要相互订阅并接受他们收到的订阅请求。让我们称他们为爱丽丝和鲍勃。Alice 向 Bob 发送订阅请求:
Presence subscribe = new Presence(Presence.Type.subscribe);
subscribe.setTo('bob@example.com');
connection.sendPacket(subscribe);
当 Bob 收到请求时,他会批准它:
Presence subscribed = new Presence(Presence.Type.subscribed);
subscribed.setTo('alice@example.com');
connection.sendPacket(subscribed);
鲍勃也可能对爱丽丝的存在感兴趣,所以他订阅了她:
Presence subscribe = new Presence(Presence.Type.subscribe);
subscribe.setTo('alice@example.com');
connection.sendPacket(subscribe);
爱丽丝需要批准鲍勃的请求:
Presence subscribed = new Presence(Presence.Type.subscribed);
subscribed.setTo('bob@example.com');
connection.sendPacket(subscribed);
RFC6121 的第 3.1 节是当前有关其工作原理的最佳参考。