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

标签 android authentication xmpp smack

我目前正在开发 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/

相关文章:

android - 在android中存储大数据

authentication - 使用用于 AzureBearerAuthentication 的 JWT 获取访问 token

c# - 如何减少 ASP.NET Core 中的 cookie 大小(类似于使用引用模式)?

android - 使用 openfire -Android 在 smack 中更新和检索聊天记录

java - 无法构建 android 项目,因为 ActionBarActivity 无法解析为类型

android - 从 iOS 移植到 Android - 我需要多少测试设备?

node.js - NodeJS - 访问套接字内的 session

php - 如何从 php 或使用 ejabberd 的直接命令创建 MUC 房间

android - 无法将 Android 客户端与本地 XMPP 服务器连接

android - 不能同时使用 `BottomNavigationView` 和 `ViewPager` 和 `TabLayout`