【问题标题】:'remote-server-timeout' exception as I try to connect to the server当我尝试连接到服务器时出现“远程服务器超时”异常
【发布时间】:2026-02-10 14:55:01
【问题描述】:

在尝试通过以下代码连接到 openfire 服务器时:

Connection connection = new XMPPConnection("https://192.168.0.101:5222");
connection.connect();

我得到一个例外,上面写着:

https://192.168.0.101:5222:5222 Exception: Could not connect 
to https://192.168.0.101:5222:5222.; : remote-server-timeout(504)

这可能是什么原因?

注意:我已经允许openfire fire服务器通过防火墙。我也尝试关闭防火墙,但结果相同。服务器是我自己的机器。我正在尝试运行程序的同一台机器。

【问题讨论】:

  • 您的网络是否正常工作...已在代码中检查...
  • @karan421 123 123..是的,它正在工作
  • ping ip 地址并查看响应时间并查看使用wireshark 会发生什么
  • @SuhailGupta 你不需要输入端口。new XMPPConnection("192.168.0.101") 很好
  • 你正在使用哪个操作系统

标签: java xmpp openfire smack


【解决方案1】:

你可以使用

Connection connection = new XMPPConnection("192.168.0.101");
connection.connect();

或者如果你想指定端口

ConnectionConfiguration config = new ConnectionConfiguration("192.168.0.101", 5222);
Connection connection = new XMPPConnection(config);   
connection.connect();

或类似的,默认为端口 5222

ConnectionConfiguration config = new ConnectionConfiguration("192.168.0.101");
Connection connection = new XMPPConnection(config);
connection.connect();

【讨论】:

    【解决方案2】:

    试试这个:

    Connection connection = new XMPPConnection("localhost:5222");
    connection.connect();
    

    【讨论】:

      【解决方案3】:

      你可以参考这个:

      public XMPPConnection(String serviceName, CallbackHandler callbackHandler) {
          // Create the configuration for this new connection
          super(new ConnectionConfiguration(serviceName));
          config.setCompressionEnabled(false);
          config.setSASLAuthenticationEnabled(true);
          config.setDebuggerEnabled(DEBUG_ENABLED);
          config.setCallbackHandler(callbackHandler);
      }
      

      或者没有用于密钥库密码提示的回调处理程序:

      public XMPPConnection(String serviceName) {
          // Create the configuration for this new connection
          super(new ConnectionConfiguration(serviceName));
          config.setCompressionEnabled(false);
          config.setSASLAuthenticationEnabled(true);
          config.setDebuggerEnabled(DEBUG_ENABLED);
      }
      

      或:

      public XMPPConnection(ConnectionConfiguration config) {
          super(config);
      }
      

      【讨论】: