asmact自動重連要能進行,那麼asmact必須要使用ReconnectionManager類。可是在asmact的ConnectionConfiguration源碼中,沒有任何加載ReconnectionManager類的代碼,是以在用戶端單獨使用如下設定是不起作用的:
configuration.setReconnectionAllowed(true);
還需在代碼前靜态加載ReconnectionManager,重連才能正常工作:
static{
try{
Class.forName("org.jivesoftware.smack.ReconnectionManager");
}catch(Exception e){
e.printStackTrace();
}
}
完成後測試,不管是斷網還是openfire伺服器重新開機情況下,用戶端都會自動重連(如果直接在伺服器上關閉會話,是不會重連的)。自動重連的時候,會自動登陸。是以所自己手動重連的代碼全删掉吧