1

现在我正在使用 ejabberd 服务器使用 XMPP-chat for Android。

当我尝试连接到服务器时,它显示错误。但它在 openfire 服务器中运行良好。

我在用smack library.

错误日志如下:

04-21 20:34:16.824: I/XMPPChatDemoActivity(1929): [SettingsDialog] 连接到 10.0.2.2 04-21 20:34:21.932: E/XMPPChatDemoActivity(1929): 以 test3@eworks.com 登录失败04-21 20:34:21.932:E/XMPPChatDemoActivity(1929):服务器没有响应。

4

1 回答 1

2

我找到了如何使用 Smack 3.1.0 连接到 gtalk 和 jabber.org 的解决方案:

GTalk 的代码:

ConnectionConfiguration cc = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com");
XMPPConnection connection = new XMPPConnection(cc);
try {
     connection.connect();

     // You have to put this code before you login
     SASLAuthentication.supportSASLMechanism("PLAIN", 0);

     // You have to specify your gmail addres WITH @gmail.com at the end
     connection.login("some.account@gmail.com", "password", "resource");

     // See if you are authenticated
     System.out.println(connection.isAuthenticated());

} catch (XMPPException e1) {
     e1.printStackTrace();
}

对于 jabber.org,这里是代码:

ConnectionConfiguration cc = new ConnectionConfiguration("jabber.org", 5222, "jabber.org");
XMPPConnection connection = new XMPPConnection(cc);
try {
     connection.connect();

     // You have to put this code before you login
     SASLAuthentication.supportSASLMechanism("PLAIN", 0);

     // You have to specify your Jabber ID addres WITHOUT @jabber.org at the end
     connection.login("your.jabber", "password", "resource");

     // See if you are authenticated
     System.out.println(connection.isAuthenticated());

} catch (XMPPException e1) {
     e1.printStackTrace();
}

使用此代码,我现在可以连接到我的本地 ejabberd 和 openfire 服务器。我希望这能解决你的问题。

于 2013-04-22T05:41:54.753 回答