XMPP,Smack,Openfire 异常、问题总结

一、Smack 4.2.3,入群时总是报无响应,还未找到原因(源码问题),已找到原因,openfire4.2.0+版本自身bug,不支持用户110状态

Exception=org.jivesoftware.smack.SmackException$NoResponseException: 
No response received within reply timeout. Timeout was 10000ms (~10s).
Waited for response using: AndFilter: (StanzaTypeFilter: Presence,
OrFilter: (AndFilter: (FromMatchesFilter (ignoreResourcepart): 
100001_ir1jbcntb@conference.192.168.1.102,
MUCUserStatusCodeFilter: status=110), AndFilter: 
(FromMatchesFilter (full): 100001_ir1jbcntb@conference.192.168.1.102/100004, 
StanzaIdFilter: id=ovR90-45, PresenceTypeFilter: type=error)))

二、加入聊天室时报错:原因,房间设置了只允许成员加入,当前账号非加入房间的成员,故报错

org.jivesoftware.smack.XMPPException$XMPPErrorException: XMPP error reply received from 
09agyrmgm@conference.localhost/哦哦等等: XMPPError: registration-required - auth

http://web.mit.edu/svalente/lib/smack_3_0_4/javadoc/org/jivesoftware/smack/packet/XMPPError.html

三、Openfire4.2.0+
发扩展消息时,message.addExtension,对方无法收到消息,Openfire4.1.6-正常,Openfire自身bug

四、AccountManager.getInstance(this.getXMPPConnection()).getAccountAttribute(“name”);无响应

04-21 11:36:16.788 14572-14640/com.xx W/System.err: org.jivesoftware.smack.SmackException$NoResponseException: No response received within reply timeout. Timeout was 10000ms (~10s). Waited for response using: StanzaIdFilter: id=nMrxy-57.
04-21 11:36:16.788 14572-14654/com.xx W/art: Long monitor contention with owner Thread-4 (14640) at void java.lang.Object.wait!(long, int)(Object.java:-2) waiters=0 in void org.jivesoftware.smackx.iqregister.AccountManager.getRegistrationInfo() for 9.936s
04-21 11:36:16.788 14572-14640/com.xx W/System.err:     at org.jivesoftware.smack.StanzaCollector.nextResultOrThrow(StanzaCollector.java:260)
04-21 11:36:16.788 14572-14640/com.xx W/System.err:     at org.jivesoftware.smack.StanzaCollector.nextResultOrThrow(StanzaCollector.java:214)
04-21 11:36:16.789 14572-14640/com.xx W/System.err:     at org.jivesoftware.smackx.iqregister.AccountManager.getRegistrationInfo(AccountManager.java:370)
04-21 11:36:16.789 14572-14640/com.xx W/System.err:     at org.jivesoftware.smackx.iqregister.AccountManager.getAccountAttribute(AccountManager.java:210)

解决找了个简单的demo,使用同样的版本,在代码中登录后加入获取name的这行代码,发现没有问题。很是奇怪,是自己写代码写的有问题?于是各种尝试,先是修改Smack版本,无果。最后修改
AccountManager.getInstance(this.getXMPPConnection()).getAccountAttribute(“name”)代码的位置,竟然没有报异常了,再修改到原来的位置,又报无响应了。原来代码中我自己定义了一个向服务端某个插件发包的语句,发包后收到结果会加入群组的操作A,但是很奇怪,这些操作都是异步的,为何会影响到获取name呢,看了下获取name的实现,也是向服务端发包,但是还是不明白原因,不过把获取name的代码挪到A前面,确实没有报错了。这个问题算是解决了,后续再深究原因吧

最终分析原因:自己写的自定义XMPP协议解析有问题。已更正
文章更新于2018年4月22日 22:14

登录时报错,原因 账号密码输入错误:

05-23 09:31:34.734 20320-20430/com.jiaxun.aruil D/XMPP_SMACK: SENT: <auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>ADEwMDEAZTEwYWRjMzk0OWJhNTlhYmJlNTZlMDU3ZjIwZjg4M2U=</auth>
05-23 09:31:34.735 20320-20343/com.jiaxun.aruil D/SessionLooperHandler: handleMessage finished
05-23 09:31:34.744 20320-20431/com.jiaxun.aruil D/XMPP_SMACK: RECV: <failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure>
05-23 09:31:34.747 20320-20420/com.jiaxun.aruil W/XmppService: org.jivesoftware.smack.sasl.SASLErrorException: SASLError using PLAIN: not-authorized
                                                                   at org.jivesoftware.smack.SASLAuthentication.authenticationFailed(SASLAuthentication.java:365)
                                                                   at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1044)
                                                                   at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPConnection.java:948)
                                                                   at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:963)
                                                                   at java.lang.Thread.run(Thread.java:818)
05-23 09:31:35.407 397-483/system_process D/TaskPersister: removeObsoleteFile: deleting file=6795_task.xml
05-23 09:31:35.408 397-483/system_process D/TaskPersister: removeObsoleteFile: deleting file=6795_task_thumbnail.png

注册时报错,原因:ejabberd服务端没配置(默认只允许带内注册)。XMPPError: forbidden - auth

05-23 20:36:09.460 10826-10884/com.wqx.dowa W/System.err: org.jivesoftware.smack.XMPPException$XMPPErrorException: XMPP error reply received from 123.56.30.171: XMPPError: forbidden - auth
05-23 20:36:09.460 10826-10884/com.wqx.dowa W/System.err:     at org.jivesoftware.smack.StanzaCollector.nextResultOrThrow(StanzaCollector.java:263)
05-23 20:36:09.460 10826-10884/com.wqx.dowa W/System.err:     at org.jivesoftware.smack.StanzaCollector.nextResultOrThrow(StanzaCollector.java:214)
05-23 20:36:09.460 10826-10884/com.wqx.dowa W/System.err:     at org.jivesoftware.smackx.iqregister.AccountManager.createAccount(AccountManager.java:288)
05-23 20:36:09.460 10826-10884/com.wqx.dowa W/System.err:     at org.jivesoftware.smackx.iqregister.AccountManager.createAccount(AccountManager.java:254)
05-23 20:36:09.460 10826-10884/com.wqx.dowa W/System.err:     at com.wqx.dowa.smack.SmackImpl.register(SmackImpl.java:1229)
05-23 20:36:09.460 10826-10884/com.wqx.dowa W/System.err:     at com.wqx.dowa.activity.RegisterActivity$20.run(RegisterActivity.java:689)
05-23 20:36:09.461 10826-10884/com.wqx.dowa W/System.err:     at java.lang.Thread.run(Thread.java:761)

05-23 20:36:09.461 10826-10894/com.wqx.dowa D/SMACK: RCV PKT (1): <iq from='123.56.30.171' id='0pqDR-13' type='error'><error type='auth'><forbidden xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/><text xmlns='urn:ietf:params:xml:ns:xmpp-stanzas' xml:lang='en'>Access denied by service policy</text></error></iq>
05-23 20:36:39.389 10826-10890/com.wqx.dowa D/SMACK: RECV (0): <stream:error><connection-timeout xmlns='urn:ietf:params:xml:ns:xmpp-streams'/><text xml:lang='en' xmlns='urn:ietf:params:xml:ns:xmpp-streams'>Idle connection</text></stream:error></stream:stream>
05-23 20:36:39.393 10826-10893/com.wqx.dowa D/SMACK: RECV (1): <stream:error><connection-timeout xmlns='urn:ietf:params:xml:ns:xmpp-streams'/><text xml:lang='en' xmlns='urn:ietf:params:xml:ns:xmpp-streams'>Idle connection</text></stream:error></stream:stream>
05-23 20:36:39.401 10826-10893/com.wqx.dowa W/AbstractXMPPConnection: Connection XMPPTCPConnection[not-authenticated] (1) closed with error
                                                                      org.jivesoftware.smack.XMPPException$StreamErrorException: connection-timeout You can read more about the meaning of this stream error at http://xmpp.org/rfcs/rfc6120.html#streams-error-conditions
                                                                      <stream:error><connection-timeout xmlns='urn:ietf:params:xml:ns:xmpp-streams'/><text xml:lang='en'>Idle connection</text></stream:error>
                                                                          at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1064)
                                                                          at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPConnection.java:1000)
                                                                          at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:1016)
                                                                          at java.lang.Thread.run(Thread.java:761)

ejabberd配置mysql数据库后,异常SASLError using SCRAM-SHA-1: not-authorized

05-24 12:30:35.740 24600-24698/com.wqx.dowa I/XmppService: LogUtils:XXException e=com.wqx.dowa.exception.XXException: SASLError using SCRAM-SHA-1: not-authorized
05-24 12:30:35.741 24600-24698/com.wqx.dowa I/com.wqx.dowa.service.XmppService: LogUtils:XMPPException in doConnect():
05-24 12:30:35.741 24600-24698/com.wqx.dowa W/System.err: com.wqx.dowa.exception.XXException: SASLError using SCRAM-SHA-1: not-authorized
05-24 12:30:35.742 24600-24698/com.wqx.dowa W/System.err:     at com.wqx.dowa.smack.SmackImpl.login(SmackImpl.java:536)
05-24 12:30:35.742 24600-24698/com.wqx.dowa W/System.err:     at com.wqx.dowa.service.XmppService$1.run(XmppService.java:230)
05-24 12:30:35.748 24600-24600/com.wqx.dowa I/LoginActivity: LogUtils:LoginActivity connectionStatusChanged connectedState=-1
05-24 12:30:35.748 24600-24600/com.wqx.dowa I/LoginActivity: LogUtils:LoginActivity connectionStatusChanged reason=SASLError using SCRAM-SHA-1: not-authorized
05-24 12:30:35.875 23178-24436/? I/SendBroadcastPermission: action:com.taobao.accs.intent.action.CONNECTINFO, mPermissionType:0

XMPPError: bad-request - modify error create new user using smack library 4.1.4 and openfire
使用openfir+smack4.1.4注册的时候 报错bad-request- modify

解决方法:

设置适当的服务名称 不要使用原始的(127.0.0.1)

登录openfire管理界面后会显示服务器名称 把那个名称设置上去就行了 下面是我的代码

 XMPPTCPConnectionConfiguration xmpp = XMPPTCPConnectionConfiguration.builder()
                    //服务器IP地址
                    .setHost("192.168.1.155")
                    //服务器端口
                    .setPort(5222)
                    //服务器名称(管理界面的 主机名)
//                    .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

12:02.657 5810-5922/com.jiaxun.aruil W/AbstractXMPPConnection: Connection closed with error
                                                                        java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)
                                                                            at libcore.io.IoBridge.maybeThrowAfterRecvfrom(IoBridge.java:592)
                                                                            at libcore.io.IoBridge.recvfrom(IoBridge.java:556)
                                                                            at java.net.PlainSocketImpl.read(PlainSocketImpl.java:485)
                                                                            at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:37)
                                                                            at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:237)
                                                                            at java.io.InputStreamReader.read(InputStreamReader.java:231)
                                                                            at java.io.BufferedReader.read(BufferedReader.java:325)
                                                                            at org.jivesoftware.smack.util.ObservableReader.read(ObservableReader.java:41)
                                                                            at org.kxml2.io.KXmlParser.fillBuffer(KXmlParser.java:1515)
                                                                            at org.kxml2.io.KXmlParser.peekType(KXmlParser.java:992)
                                                                            at org.kxml2.io.KXmlParser.next(KXmlParser.java:349)
                                                                            at org.kxml2.io.KXmlParser.next(KXmlParser.java:313)
                                                                            at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1169)
                                                                            at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPConnection.java:948)
                                                                            at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:963)
                                                                            at java.lang.Thread.run(Thread.java:818)
                                                                         Caused by: android.system.ErrnoException: recvfrom failed: ECONNRESET (Connection reset by peer)
                                                                            at libcore.io.Posix.recvfromBytes(Native Method)
                                                                            at libcore.io.Posix.recvfrom(Posix.java:185)
                                                                            at libcore.io.BlockGuardOs.recvfrom(BlockGuardOs.java:250)
                                                                            at libcore.io.IoBridge.recvfrom(IoBridge.java:553)
                                                                            at java.net.PlainSocketImpl.read(PlainSocketImpl.java:485) 
                                                                            at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:37) 
                                                                            at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:237) 
                                                                            at java.io.InputStreamReader.read(InputStreamReader.java:231) 
                                                                            at java.io.BufferedReader.read(BufferedReader.java:325) 
                                                                            at org.jivesoftware.smack.util.ObservableReader.read(ObservableReader.java:41) 
                                                                            at org.kxml2.io.KXmlParser.fillBuffer(KXmlParser.java:1515) 
                                                                            at org.kxml2.io.KXmlParser.peekType(KXmlParser.java:992) 
                                                                            at org.kxml2.io.KXmlParser.next(KXmlParser.java:349) 
                                                                            at org.kxml2.io.KXmlParser.next(KXmlParser.java:313) 
                                                                            at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1169) 
                                                                            at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPConnection.java:948) 
                                                                            at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:963) 
                                                                            at java.lang.Thread.run(Thread.java:818) 
07-17 19:12:02.658 5810-5922 D/XmppService: connectionClosedOnError   e=java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)

当调用connection时,报No longer connection异常,而又可以收到消息
排查,重新连接后,没有将新的connection设置给一个全局变量mConnection中,调用方法A时使用的还是之前的connection,故可以收到消息,但是发送消息(使用的旧connection)时失败

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/w690333243/article/details/79969088
个人分类: xmpp smack
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭