[英]Unable to login using smack XMPP client in Android
trying to connect & login using XMPP client in Android. 尝试在Android中使用XMPP客户端进行连接和登录。 The XMPP client connects to the server but doesn't logs in. I am getting Exception message as No response from the server.
XMPP客户端连接到服务器,但未登录。我收到异常消息,因为服务器未响应。
i have google and found the same issue here but its not working for me. 我有谷歌,并在这里找到相同的问题,但对我不起作用。
my code is 我的代码是
// 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);
}
i am unable to figure where the problem is? 我无法弄清楚问题出在哪里?
Edit: the same code is working fine (loggin the user) from google.com but not working for my ejabberd XMPP client y? 编辑:相同的代码可以从google.com正常运行(登录用户),但不适用于我的ejabberd XMPP客户端y?
In the Second Try and catch You have to write as connection.login("UserName","Password"); 在第二次尝试中,您必须编写为connection.login(“ UserName”,“ Password”);。
and after connection .sendPacket(presence); 和连接后.sendPacket(presence); You have to write only as setConnection(connection);
您只需要写为setConnection(connection);
which May be helpful to you. 可能对您有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.