今天客户在用程序的时候发现安卓6.0.1的程序死活不能登陆,但是获取版本号或者在6.0以下的手机上时没问题的! 看了下是xmpp链接除了问题,查了查发现当登陆的时候会出现“No response from the server”!
发现:
XMPPConnection connection = new XMPPConnection(getConfig(xmppPort));
connection.connect();返回是链接成功的;然后发现“No response from the server”出现在2个地方:
1:
IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); if (response == null) { throw new XMPPException("No response from the server."); }
2: 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."); }
所以resource bind失败,或者确实没有收到response包。smack又是一个封装的库,参数只有用户名,密码和SecurityMode了。所有最后发现问题出现在了TLS链路上。所以改了下默认的enable为disable,问题立即解决,虽说安全系数下降,但是找了好久只有找到这个方法了。如果你们有好的方法,可以给我留言啊!
最后贴上修改后的代码:
ConnectionConfiguration config = new ConnectionConfiguration(GlobalConstant.XMPPServerName, Integer.valueOf(xmppPort)); config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);//这是要修改的部门,上边只是实例。