用户名为在他的名册中tester
添加了另一个用户sanika
。订阅模式sanika
设置为Roster.SubscriptionMode.accept_all
。但是当tester
检查sanika
他的状态时subscribe
。为什么会这样?
在 main 函数中,sanika
设置她的状态,在函数connectTester
tester 中,尝试获取 的状态sanika
。
public static void main(String[] args) {
try {
Connection connection = new XMPPConnection("localhost");
connection.connect();
connection.login("sanika", "tester");
Roster r = connection.getRoster();
r.setSubscriptionMode(Roster.SubscriptionMode.accept_all);
Presence p = new Presence(Presence.Type.available);
p.setStatus("Having Lunch :)");
connection.sendPacket(p);
connectTester();
Thread.sleep(30000);
} catch(Exception exc) {
exc.printStackTrace();
}
}
public static void connectTester() {
try {
Connection connection = new XMPPConnection("localhost");
connection.connect();
connection.login("tester", "tester");
Roster r = connection.getRoster();
RosterEntry re = r.getEntry("sanika@sanika.com");
System.out.println(re.getStatus().toString());
// PRINTS SUBSCRIBE
}catch(Exception exc) {}
我在哪里犯错了?
注意: tester
添加sanika
为:
String group[] = {"Friend List"};
r.createGroup("Friend List");
r.createEntry("sanika@sanika.com", "sanika", group);