尝试连接&在Android中使用XMPP客户端登录。 XMPP客户端连接到服务器但没有登录。我收到Exception消息为服务器没有响应。
我有谷歌并发现同样的问题here,但它不适合我。
我的代码是
// Create a connection
ConnectionConfiguration connConfig = new ConnectionConfiguration(host,
5222, service);
XMPPConnection connection = new XMPPConnection(connConfig);
try {
connection.connect();
Log.i("XMPPClient", "Connected to " + connection.getHost());
} catch (XMPPException ex) {
Log.e("XMPPClient", " Failed to connect to " + connection.getHost());
Log.e("XMPPClient", ex.toString());
xmppClient.setConnection(null);
}
try {
connection.login("username", "userpass", "someresource");
Log.i("XMPPClient", "Logged in as " + connection.getUser());
// Set the status to available
Presence presence = new Presence(Presence.Type.available);
connection.sendPacket(presence);
xmppClient.setConnection(connection);
} catch (XMPPException ex) {
Log.e("XMPPClient", "[SettingsDialog] Failed to log in as "
+ USERNAME);
Log.e("XMPPClient", ex.toString());
xmppClient.setConnection(null);
}
我无法确定问题出在哪里?
编辑:相同的代码在google.com上工作正常(登录用户)但不适用于我的ejabberd XMPP客户端y?
答案 0 :(得分:0)
在第二次尝试和捕获中你必须写为connection.login(" UserName","密码");
和连接后.sendPacket(在场);您只需要编写为setConnection(connection);
可能对您有所帮助。