【问题标题】:OpenFire Server check connection for XMPPOpenFire 服务器检查 XMPP 的连接
【发布时间】:2016-04-16 17:50:24
【问题描述】:

我在我的应用程序中使用了 open fire,但我无法检查我的用户是否与服务器连接,请建议我如何检查。

【问题讨论】:

  • 到目前为止你尝试了什么?你能发布代码吗?而openfire是用于您使用过的客户端的服务器端? asmack , smack 还是什么?
  • 检查给出的答案方法:-

标签: android openfire


【解决方案1】:

检查这个给定的方法

 public XMPPConnection connect(final String username, final String password,
                              final String host, final String service, final String port) {
    // Create a connection
    ConnectionConfiguration connConfig = new ConnectionConfiguration(host, Integer.parseInt(port), service);
    connConfig.setSASLAuthenticationEnabled(false);


    try {
        connection = new XMPPConnection(connConfig);
        connection.connect();
        Log.i("XMPPClient",
                "[SettingsDialog] Connected to " + connection.getHost());
    } catch (XMPPException ex) {
        Log.e("XMPPClient", "[SettingsDialog] Failed to connect to "
                + connection.getHost());
        Log.e("XMPPClient", ex.toString());
    }

    //Login to the server
    try {
        connection.login(username, password, "Smack" + new Date().getTime());
        Log.i("XMPPClient", "Logged in as " + connection.getUser());
        Presence presence = new Presence(Presence.Type.available);// Set the presence to available
        connection.sendPacket(presence);
    } catch (XMPPException ex) {
        Log.e("XMPPClient", "[SettingsDialog] Failed to log in as " + username);
        Log.e("XMPPClient", ex.toString());
        return null;
    }
    //initialize();


    initialize();//Add packet listener on connection for listen any message received

    return connection;
}

此连接对象将帮助您找到您的用户是否已连接

【讨论】:

    猜你喜欢
    • 2013-10-07
    • 1970-01-01
    • 1970-01-01
    • 2012-04-16
    • 2013-08-27
    • 2014-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多