【问题标题】:Unable to connect to local Openfire server (using smack api)无法连接到本地 Openfire 服务器(使用 smack api)
【发布时间】:2015-05-15 23:35:29
【问题描述】:

我正在 android 上尝试此代码以连接到我的本地 XMPP 服务器

Thread t = new Thread(new Runnable() {
        @Override
        public void run() {
            // Create a connection
            ConnectionConfiguration connConfig = new ConnectionConfiguration(
                    "192.168.43.170", 5223, "192.168.43.170");
            XMPPConnection connection = new XMPPConnection(connConfig);

            try {
                connection.connect();
            } catch (XMPPException ex) {
            }
            try {
                // SASLAuthentication.supportSASLMechanism("PLAIN", 0);
                connection.login("nagham","123456");
                // Set the status to available
                Presence presence = new Presence(Presence.Type.available);
                connection.sendPacket(presence);
                setConnection(connection);
                Roster roster = connection.getRoster();
                Collection<RosterEntry> entries = roster.getEntries();
                for (RosterEntry entry : entries) {
                    Presence entryPresence = roster.getPresence(entry
                            .getUser());

                    Presence.Type type = entryPresence.getType();
                }
            } catch (XMPPException ex) {    
        }
        }
    });

但我得到以下异常:

    05-16 02:10:16.580: E/XMPPChatDemoActivity(24289): Failed to connect to 192.168.43.170
05-16 02:10:16.588: E/XMPPChatDemoActivity(24289): XMPPError connecting to 192.168.43.170:5223.: remote-server-error(502) XMPPError connecting to 192.168.43.170:5223.
05-16 02:10:16.588: E/XMPPChatDemoActivity(24289):   -- caused by: java.net.ConnectException: failed to connect to /192.168.43.170 (port 5223): connect failed: ETIMEDOUT (Connection timed out)
05-16 02:10:16.588: E/AndroidRuntime(24289): FATAL EXCEPTION: Thread-5736
05-16 02:10:16.588: E/AndroidRuntime(24289): java.lang.IllegalStateException: Not connected to server.

我哪里错了? 请注意,我使用的是 asmack-2010.05.07

【问题讨论】:

  • 不要使用旧的 SSL(5223) 连接,尝试 5222 端口
  • 是的,谢谢我更改了端口号,我注意到我的实验室上的防火墙正在运行,所以当我禁用它时,一切都会继续

标签: android xmpp smack


【解决方案1】:

我已经解决了我的问题,只是将端口号从 5223 更改为 5222 并且每个人都不要忘记必须禁用您的防火墙。

【讨论】:

    猜你喜欢
    • 2015-07-27
    • 1970-01-01
    • 2021-01-16
    • 2015-09-19
    • 2015-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多