连接到 xmpp 服务器

connect to xmpp server

我尝试通过此代码连接到我的 xmpp 服务器

    final String servicename = "my server ip";  
    XMPPTCPConnection connection;


    public void Register(String userName, String password)throws XMPPException, SmackException, IOException
    {
   try{
          XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
          .setServiceName(servicename)
          .setUsernameAndPassword("admin username", "admin password")
          .setCompressionEnabled(false).build();

          connection = new XMPPTCPConnection(config);

          connection.connect();
          AccountManager AM = AccountManager.getInstance(connection);
          AM.createAccount(userName, password);
          connection.disconnect();
          System.out.println(":)");
     } 
     catch(XMPPException e){
          System.out.println(":(");            
     }

    }

所有代码都在 try catch 中,但是当我调用此函数时,没有任何内容被打印出来并出现错误。

我是 java 的新手,但我认为配置声明出现错误

我从 here

复制配置声明

我该如何解决这个问题?

提前致谢

我终于发现 answer.it 似乎在 smack 4 之后你需要向你的项目添加更多的 jar 文件,其中一个解决了我的问题是 this