我试图连接到服务器时出现’remote-server-timeout’exception
在尝试通过以下代码连接到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服务器通过防火墙。我也试过推迟防火墙,但结果相同.Server是我自己的机器。 我正在尝试运行程序的同一台机器。
您可以使用
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();
试试这个:
Connection connection = new XMPPConnection("localhost:5222"); connection.connect();
你可以参考这个:
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); }