Smack API 在本地登录 Tigase 服务器设置时出错

Posted

技术标签:

【中文标题】Smack API 在本地登录 Tigase 服务器设置时出错【英文标题】:Smack API giving error while logging into Tigase Server setup locally 【发布时间】:2010-06-04 20:28:14 【问题描述】:

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

以下是我正在使用的代码的sn-p

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 文件,它看起来与链接解决方案中给出的相同。

谢谢, 阿美亚

【问题讨论】:

【参考方案1】:

我找到了here中给出的问题的解决方案

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

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

感谢大家的帮助

【讨论】:

【参考方案2】:

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

【讨论】:

我应该怎么做才能使它正常工作。我用 Gtalk 服务器尝试了相同的代码并且它工作正常。所以我想问题是服务器的设置(一些资源问题)。我应该在服务器端做些什么吗?

以上是关于Smack API 在本地登录 Tigase 服务器设置时出错的主要内容,如果未能解决你的问题,请参考以下文章

在 Tigase 中向客户端发送自定义消息

无法连接到本地 Openfire 服务器(使用 smack api)

如何使用 Smack XMPP API 处理(失败的)登录尝试

使用 XMPP 协议通过 tigase 服务器将字符串数组从一个 Android 发送到另一个

XMPP 注销(Smack API)

使用 smack api 连接到 openfire 服务器