尝试通过以下代码连接到 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是我自己的机器。我正在尝试运行程序的同一台机器。
答案 0 :(得分:2)
您可以使用
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();
答案 1 :(得分:0)
试试这个:
Connection connection = new XMPPConnection("localhost:5222");
connection.connect();
答案 2 :(得分:0)
您可以参考以下内容:
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);
}