异常:
openfire服务端配置域名为127.0.0.1 服务名 127.0.0.1 即openfire安装在本机电脑,客户端访问本地服务器。
电脑上的spark配置域名为127.0.0.1,可以正常登录
用自己写的app客户端连接时配置的服务器IP也为127.0.0.1,登录后出现如下异常
org.jivesoftware.smack.SmackException$ConnectionException: The following addresses failed: ‘127.0.0.1:5222’ failed because: /127.0.0.1 exception: java.net.ConnectException: Connection refused
at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectUsingConfiguration(XMPPTCPConnection.java:619)
at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectInternal(XMPPTCPConnection.java:902)
at org.jivesoftware.smack.AbstractXMPPConnection.connect(AbstractXMPPConnection.java:380)
03-25 06:03:40.376 10956-11115/com.wqx.dowa W/System.err: at com.wqx.dowa.smack.SmackImpl.login(SmackImpl.java:287)
解决:cmd命令,ipconfig,查看本机ip,app客户端连接的ip换为本机ip,不再使用127.0.0.1。openfire配置不变,正常登录
不建议这么做,最好openfie服务端配置的域名,服务器地址和客户端保持一致。
发送消息:
app使用smark4.2的时候,远程服务端(阿里云主机)openfire使用4.1.5,群聊(新加的功能)怎么都收不到消息,也发不出去,一直找不到问题所在。
最后先在本地试试的心态(怀疑是服务器openfire版本的问题,毕竟4.2版本改动了很多),在本地安装openfire4.2.3,登录成功后,群聊收发消息正常。确定是服务端openfire版本低的问题。
注意:4.2后发消息时:
单聊/群聊 这样写
Message newMessage;
newMessage = new Message(JidCreate.from(toJID));
newMessage.setBody(messageBody);
mXMPPConnection.sendStanza(newMessage);
单聊时,对方可以收到消息,提示是广播的消息。
群聊时,群成员收不到消息
正确写法:
单聊:
Message newMessage;
newMessage = new Message(JidCreate.from(toJID),Message.Type.chat);
newMessage.setBody(messageBody);
mXMPPConnection.sendStanza(newMessage);
群聊:
Message newMessage;
newMessage = new Message(JidCreate.from(toJID),Message.Type.groupchat);
newMessage.setBody(messageBody);
mXMPPConnection.sendStanza(newMessage);
阿里云上安装openfire:
xftp工具下载 https://download.csdn.net/download/qq_35841826/10131415
xshell 工具
openfire4.2.3
rpm 在ubuntu下安装 方法 https://blog.csdn.net/suleil1/article/details/49471723
方法:
1.CODE:
sudo apt-get install rpm alien
2.CODE:
alien -d package.rpm
3.CODE:
sudo dpkg -i package.deb
XMPPError: bad-request - modify error create new user using smack and openfire
解决方法:
设置适当的服务名称 不要使用原始的()
登录openfire管理界面后会显示服务器名称 把那个名称设置上去就行了 下面是我的代码
XMPPTCPConnectionConfiguration xmpp = XMPPTCPConnectionConfiguration.builder()
//服务器IP地址
.setHost("192.168.1.155")
//服务器端口
.setPort()
//服务器名称(管理界面的 主机名)
// .setServiceName("127.0.0.1") 不设置默认的地址
.setServiceName("user-20150810nb")
//是否开启安全模式
.setSecurityMode(XMPPTCPConnectionConfiguration.SecurityMode.disabled)
//是否开启压缩
.setCompressionEnabled(false)
.setSendPresence(false)
//开启调试模式
.setDebuggerEnabled(true)
.setUsernameAndPassword("admin", "admin")
.build();
https://blog.csdn.net/u011481547/article/details/72842738