打击存在不起作用

2024-02-21

实际上我使用 smack API 编写了一个 IM 服务(继承了 google chat)。但是当我想打印好友列表及其存在时,编译模式显示所有存在不可用,但在调试模式下它显示真正的可用性!

我的代码是...

1-创建连接

public boolean openConnection() {
    ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration("talk.google.com", 5222, "mail.google.com");
    this.connection = new XMPPConnection(connectionConfiguration);
    try {
        this.connection.connect();
    } catch (XMPPException e) {
        // TODO: Send Error Information To Programmer's Email Address
    }
    if(this.connection.isConnected()) {
        this.roster = this.connection.getRoster();
        this.roster.addRosterListener(new RosterListener() {
            public void entriesAdded(Collection<String> addresses) {}
            public void entriesDeleted(Collection<String> addresses) {}
            public void entriesUpdated(Collection<String> addresses) {}
            public void presenceChanged(Presence presence) {}
        });
        return true;
    }
    return false;
}

2- login

public boolean login(String jid, String password) {
    try { 
        this.connection.login(jid, password, "smack");
    } catch (XMPPException e) {
        // TODO: Send Error Information To Programmer's Email Address
    }
    if(this.connection.isAuthenticated()) return true;
    return false;
}

3-好友列表

public void buddiesList() {
    Collection<RosterEntry> rosterEntries = this.roster.getEntries();
    for(RosterEntry rosterEntry: rosterEntries) {
        System.out.println(rosterEntry.username() + " === " + this.roster.getPresence(rosterEntry.getUser()));
    }
}

4-实施

public static void main(String args[]) {
    IMService imService = new IMService();
    imService.openConnection();
    imService.login("google account", "password");
    imService.buddiesList();
}

您的 RosterListener 不执行任何操作。当收到状态消息之类的信息时,您必须在此处放置代码来更新您的名册。

您正在检索的存在是创建状态时的快照。为了保持状态最新,您必须实际编写 RosterListener 代码。这在《条例》中有明确规定getPresence() 的 Javadoc http://www.igniterealtime.org/builds/smack/docs/latest/javadoc/org/jivesoftware/smack/Roster.html#getPresence%28java.lang.String%29 method.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

打击存在不起作用 的相关文章

随机推荐