1

我目前正在开发 android XMPP 客户端以与本地的 Tigase 服务器设置进行通信。在开始在 Android 上进行开发之前,我正在 PC 上编写一个简单的 java 代码来测试与 XMPP 服务器的连接性。我的 XMPP 域是我的 PC 名称“mwbn43-1”和管理员用户名和密码分别为 admin 和 tigase。

以下是我正在使用的代码片段

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)

我在同一问题上找到了这篇文章,但 这里没有具体的解决方案 谁能告诉我这个问题的解决方案。我检查了 Smack API 中的 XMPPConnection.java 文件,它看起来与链接解决方案中给出的相同。

谢谢,阿米亚

4

2 回答 2

3

我找到了这里给出的问题的解决方案

这些是我连接到服务器之前应该添加的行

ConnectionConfiguration config = new ConnectionConfiguration("mwbn43-1", 5222);
config.setSASLAuthenticationEnabled(false);
XMPPConnection xmpp = new XMPPConnection(config);

感谢你的帮助

于 2010-06-07T18:37:32.743 回答
-1

我认为这是库的问题,一个错误。它不能正确处理协议。在用户通过身份验证之前,没有必要发送资源绑定,因此服务器不会通告它。客户不应该抱怨它。

于 2010-06-05T07:25:01.487 回答