我目前正在开发 android XMPP 客户端以与本地的 Tigase 服务器设置进行通信。在 Android 上开始开发之前,我正在 PC 上编写一个简单的 java 代码来测试与 XMPP 服务器的连接。我的 XMPP 域是我的电脑名称“mwbn43- 1",管理员用户名和密码分别为admin和tigase。
以下是我使用的代码 fragment
class Test {
public static void main(String args[])throws Exception
{
System.setProperty("smack.debugEnabled", "true");
XMPPConnection.DEBUG_ENABLED = true;
ConnectionConfiguration config = new ConnectionConfiguration("mwbn43-1", 5222);
config.setCompressionEnabled(true);
config.setSASLAuthenticationEnabled(true);
XMPPConnection con = new XMPPConnection(config);
// Connect to the server
con.connect();
con.login("admin", "tigase");
Chat chat = con.getChatManager().createChat("aaphadke@mwbn43-1",
new MessageListener() {
public void processMessage(Chat chat, Message message) {
// Print out any messages we get back to standard out.
System.out.println("Received message: " + message);
}
});
try {
chat.sendMessage("Hi!");
}
catch (XMPPException e) {
System.out.println("Error Delivering block");
}
String host = con.getHost();
String user = con.getUser();
String id = con.getConnectionID();
int port = con.getPort();
boolean i = false;
i = con.isConnected();
if (i)
System.out.println("Connected to host " + host + " via port " + port + " connection id is " + id);
System.out.println("User is " + user);
con.disconnect();
}
}
当我运行这段代码时,出现以下错误
Exception in thread "main" Resource binding not offered by server:
at org.jivesoftware.smack.SASLAuthentication.bindResourceAndEstablishSession(SASLAuthenticatio n.java:416) at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:331)
at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:395)
at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:349)
at Test.main(Test.java:26)
我找到了这篇关于同样问题的文章,但没有具体的解决方案 here 谁能告诉我这个问题的解决方案。我检查了 Smack API 中的 XMPPConnection.java 文件,它看起来与链接解决方案中给出的相同。
谢谢, 阿米娅
最佳答案
我找到了 here 中给出的问题的解决方案
这些是我在连接到服务器之前应该添加的行
ConnectionConfiguration config = new ConnectionConfiguration("mwbn43-1", 5222);
config.setSASLAuthenticationEnabled(false);
XMPPConnection xmpp = new XMPPConnection(config);
谢谢你的帮助
关于android - 在本地登录 Tigase 服务器设置时 Smack API 出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2977572/