【问题标题】:XMPP Client on Android using SMACK v4.0.6XMPP 客户端在 Android 上使用 SMACK v4.0.6
【发布时间】:2015-04-12 13:15:42
【问题描述】:

我是使用 SMACK v4.0.6 实现 XMPP 和在 Android XMPP 客户端上工作的新手。我正在尝试使用以下代码连接到在我的本地 Linux 机器上运行的 SMACK 服务器

`ConnectionConfiguration connConfig = new ConnectionConfiguration(localServerIP, 5222);
XMPPConnection connection = new XMPPConnection(connConfig);
try{
    connection.connect();
}catch(Exception e)`.

我无法连接到服务器,我只收到一个 ConnectionException。客户端和服务器都连接到同一个本地网络,Android 应用程序有权连接到 Internet。服务器正在运行默认配置。你能告诉我我错过了什么吗?

谢谢

【问题讨论】:

标签: android xmpp openfire smack asmack


【解决方案1】:

将 smack 更新到 4.1。 在你的 gradle 中,添加

compile 'org.igniterealtime.smack:smack-android:4.1.0'
compile 'org.igniterealtime.smack:smack-tcp:4.1.0'
compile 'org.igniterealtime.smack:smack-android-extensions:4.1.0'

请试试这个。

XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();
    configBuilder.setHost(url);
    configBuilder.setPort(port);
    configBuilder.setServiceName("your service name");
    configBuilder.setSendPresence(true);

    try{
                connection = new XMPPTCPConnection(configBuilder.build());
                // Connect to the server
                connection.connect();
    }catch (XMPPException | SmackException | IOException e ) {
                e.printStackTrace();
    }

【讨论】:

    猜你喜欢
    • 2014-06-24
    • 2015-10-19
    • 1970-01-01
    • 2011-12-05
    • 2012-10-18
    • 2015-05-16
    • 2016-02-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多