为什么两侧都没有添加名单?

时间:2013-11-07 14:50:44

标签: java smack

user-auser-b发送订阅请求。订阅模式已设置为accept_all。此外,已为两个用户注册数据包侦听器

user-auser-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应用程序,我尝试将两个用户保持在线

0 个答案:

没有答案