连接不上openfire服务器

weixin_43809347 2021-03-16 09:36:30
代码如下:
new Thread(new Runnable() {
@Override
public void run() {
//先与openfire服务器建立连接
XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();
//设置XMPP域名
try {
configBuilder.setXmppDomain("127.0.0.1");
} catch (XmppStringprepException e) {
e.printStackTrace();
}
//设置主机位置(即服务器ip)
try {
InetAddress address=InetAddress.getByName("127.0.0.1");
configBuilder.setHostAddress(address);
} catch (UnknownHostException e) {
e.printStackTrace();
}
//设置端口号
configBuilder.setPort(5223);
//设置不验证,否则需要TLS验证
configBuilder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
//设置更改用户当前状态(在线、离线等)
configBuilder.setSendPresence(false);
/* configBuilder.setUsernameAndPassword("admin","xuan99102400..");*/
AbstractXMPPConnection connection = new XMPPTCPConnection(configBuilder.build());
// 连接到服务器
try {
connection.connect();
} catch (SmackException e) {
Logger.getLogger("falied");
e.printStackTrace();
}


抛出的异常如下:
org.jivesoftware.smack.SmackException$ConnectionException: The following addresses failed: 'null:5223' failed because: /127.0.0.1 exception: java.net.ConnectException: failed to connect to /127.0.0.1 (port 5223) from /127.0.0.1 (port 41318) after 30000ms: isConnected failed: ECONNREFUSED (Connection refused)

spark能连接得上服务器,会不会是android模拟器的原因。
...全文
277 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_43809347 2021-03-18
  • 打赏
  • 举报
回复
搞定了,端口改使用5222,但主要问题是我把服务器搭在127.0.0.1,模拟器默认自己是127.0.0.1,跑程序时就变成我访我自己,后来把服务器搭在PC的局域网上,就好了。
jzp12 2021-03-17
  • 打赏
  • 举报
回复
你确认是使用的是5223,而不是默认的5222? 先确认一下5223端口是否可用。

80,471

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧