执行代码聊天应用程序时出现超时错误

时间:2014-01-20 09:46:03

标签: android xampp chat

我正在尝试在android中实现聊天应用程序我收到超时错误。

以下是我的代码,

    public void connect() {

  dialog = ProgressDialog.show(this,
            "Connecting...", "Please wait...", false);

    Thread t = new Thread(new Runnable() {

        @Override
        public void run() {
            // Create a connection
            ConnectionConfiguration connConfig = new ConnectionConfiguration(
                    HOST, PORT, SERVICE);
            XMPPConnection connection = new XMPPConnection(connConfig);

            try {
                connection.connect();
                Log.i("XMPPChatDemoActivity",
                        "Connected to " + connection.getHost());
            } catch (XMPPException ex) {
                Log.e("XMPPChatDemoActivity", "Failed to connect to "
                        + connection.getHost());
                Log.e("XMPPChatDemoActivity", ex.toString());
                setConnection(null);
            }
            try {
                 SASLAuthentication.supportSASLMechanism("PLAIN", 0);
                connection.login(USERNAME, PASSWORD);
                Log.i("XMPPChatDemoActivity",
                        "Logged in as " + connection.getUser());

                // 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) {
                    Log.d("XMPPChatDemoActivity",
                            "--------------------------------------");
                    Log.d("XMPPChatDemoActivity", "RosterEntry " + entry);
                    Log.d("XMPPChatDemoActivity",
                            "User: " + entry.getUser());
                    Log.d("XMPPChatDemoActivity",
                            "Name: " + entry.getName());
                    Log.d("XMPPChatDemoActivity",
                            "Status: " + entry.getStatus());
                    Log.d("XMPPChatDemoActivity",
                            "Type: " + entry.getType());
                    Presence entryPresence = roster.getPresence(entry
                            .getUser());

                    Log.d("XMPPChatDemoActivity", "Presence Status: "
                            + entryPresence.getStatus());
                    Log.d("XMPPChatDemoActivity", "Presence Type: "
                            + entryPresence.getType());
                    Presence.Type type = entryPresence.getType();
                    if (type == Presence.Type.available)
                        Log.d("XMPPChatDemoActivity", "Presence AVIALABLE");
                    Log.d("XMPPChatDemoActivity", "Presence : "
                            + entryPresence);

                }
            } catch (XMPPException ex) {
                Log.e("XMPPChatDemoActivity", "Failed to log in as "
                        + USERNAME);
                Log.e("XMPPChatDemoActivity", ex.toString());
                setConnection(null);
            }

            dialog.dismiss();
        }
    });
    t.start();
    dialog.show();
}

有人可以建议我解决这个问题吗?

01-20 09:53:35.977: E/XMPPChatDemoActivity(3484): Failed to connect to talk.google.com
01-20 09:53:35.977: E/XMPPChatDemoActivity(3484): XMPPError connecting to talk.google.com:5222.: remote-server-error(502) XMPPError connecting to talk.google.com:5222.
01-20 09:53:35.977: E/XMPPChatDemoActivity(3484):   -- caused by: java.net.ConnectException: failed to connect to talk.google.com/74.125.135.125 (port 5222): connect failed: ETIMEDOUT (Connection timed out)
01-20 09:53:35.977: W/dalvikvm(3484): threadid=11: thread exiting with uncaught exception (group=0x40a71930)
01-20 09:53:36.047: E/AndroidRuntime(3484): FATAL EXCEPTION: Thread-114
01-20 09:53:36.047: E/AndroidRuntime(3484):     at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:217)
01-20 09:53:36.047: E/AndroidRuntime(3484):     at org.jivesoftware.smack.Connection.login(Connection.java:353)
01-20 09:53:36.047: E/AndroidRuntime(3484):     at com.demo.xmppchat.XMPPChatDemoActivity$3.run(XMPPChatDemoActivity.java:162)
01-20 09:53:36.047: E/AndroidRuntime(3484):     at java.lang.Thread.run(Thread.java:856)

0 个答案:

没有答案