XMPP: smack exception "No response from the server"
http://blog.chinaunix.net/uid-22027772-id-3013644.html
smack exception: No response from the server (注意:不是No response from server)
产生的原因有多种:
1. MessageListener未能正确处理response,详情参见
http://community.igniterealtime.org/thread/33598
2. 网络连接出现问题,smack客户端没办法收到response,详情参见(需爬墙……)
http://davanum.wordpress.com/2007/12/31/android-just-use-smack-api-for-xmpp/
今天在服务器上重现了这个问题,间歇性返回No response from the server,但是网络连接状态相当好,到该服务器的http请求都顺利返回,而且速度很快,因此不是网络连接问题。同样,并不是每次返回都报错,60%的尝试是能够成功的,因此也排除原因1
重现该exception的时候,虽然不是网络导致的原因,但是跟网络环境有密切关联:
1. 在非常稳定的网络环境下(ping值稳定在5ms左右,且没有明显的抖动)出现的概率非常小
2. 在网络抖动比较大的环境下,出现非常频繁
google说明,smack的这个exception,已经report在openfire和ejabberd上都重现过,因此证明,不是单一服务器代码的问题
通过检查smack源代码,查到No response from the server的exception出现在2个文件中:
NonSASLAuthentication.java:
Bind response = (Bind) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); collector.cancel(); if (response == null) { throw new XMPPException("No response from the server."); } IQ ack = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); collector.cancel(); if (ack == null) { throw new XMPPException("No response from the server."); }