【发布时间】: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 端口
-
是的,谢谢我更改了端口号,我注意到我的实验室上的防火墙正在运行,所以当我禁用它时,一切都会继续