user-a
向 发送订阅请求user-b
。订阅模式已设置为accept_all
。此外,已经为两个用户注册了数据包侦听器。
当向此方法user-a
发送请求时user-b
被调用:
private void searchUser(java.awt.event.ActionEvent evt) {
try {
String userToSearch = jTextField1.getText();
if(!xmppParamInit) {
initUXmppP();
xmppParamInit = true;
}
Presence subscribe = new Presence(Presence.Type.subscribe);
userToSearch += "@localhost";
subscribe.setTo(userToSearch);
ofConnection.sendPacket(subscribe); // Send the 'subscribe' packet
}catch(Exception exc) {
exc.printStackTrace();
}
}
在此方法之前,调用以下方法:
private void startPLThread() { // start packet-listener-thread
Runnable r = new Runnable() {
@Override
public void run() {
startPL();
}
};
new Thread(r,"packet listener thread").start();
}
private void startPL() {
PacketListener pListener = new PacketListener() {
@Override
public void processPacket(Packet packet) {System.out.println("Inside process packet");
if(packet instanceof Presence) {
Presence presence = (Presence) packet;
Presence subscription = new Presence(Presence.Type.subscribe);
subscription.setTo(presence.getFrom());
System.out.println("presence.getFrom : " + presence.getFrom());
ofConnection.sendPacket(subscription);
}
}
};
PacketFilter pFilter = new PacketFilter() {
@Override
public boolean accept(Packet packet) {
return true;
}
};
ofConnection.addPacketListener(pListener, pFilter);
}
问题是user-a
可以在他的花名册中看到user-b
,但在其花名册user-b
中看不到user-a
。我不明白这是为什么。可能是什么问题呢 ?
accept_all
在从搜索用户中调用的此方法中已将订阅模式设置为:
private void initUXmppP() { // Initialize user-xmpp-parameters
Roster roster = ofConnection.getRoster();
roster.setSubscriptionMode(Roster.SubscriptionMode.accept_all);
}
这是一个 GUI 应用程序,我尝试让两个用户都在线