我正在使用asmack 4.0.7和eclipse。
这是我用来连接服务器的代码:
config = new ConnectionConfiguration("192.168.43.214", 5223);
// config.setReconnectionAllowed(true);
config.setDebuggerEnabled(true);
config.setSecurityMode(SecurityMode.disabled);
connection = new XMPPTCPConnection(config);
connection.setPacketReplyTimeout(10000L);
connection.connect();
connection.login(session.getUsername(), session.getRamz());
和logcat:
org.jivesoftware.smack.SmackException$NoResponseException
at org.jivesoftware.smack.XMPPConnection.throwConnectionExceptionOrNoResponse(XMPPConnection.java:548)
at org.jivesoftware.smack.tcp.XMPPTCPConnection.throwConnectionExceptionOrNoResponse(XMPPTCPConnection.java:867)
05-14 18:17:04.348: W/System.err(6068): at org.jivesoftware.smack.tcp.PacketReader.startup(PacketReader.java:113)
05-14 18:17:04.348: W/System.err(6068): at org.jivesoftware.smack.tcp.XMPPTCPConnection.initConnection(XMPPTCPConnection.java:482)
05-14 18:17:04.348: W/System.err(6068): at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectUsingConfiguration(XMPPTCPConnection.java:440)
05-14 18:17:04.348: W/System.err(6068): at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectInternal(XMPPTCPConnection.java:811)
05-14 18:17:04.348: W/System.err(6068): at org.jivesoftware.smack.XMPPConnection.connect(XMPPConnection.java:396)
05-14 18:17:04.348: W/System.err(6068): at service.ChatService$Connect.doInBackground(ChatService.java:193)
05-14 18:17:04.348: W/System.err(6068): at service.ChatService$Connect.doInBackground(ChatService.java:1)
05-14 18:17:04.348: W/System.err(6068): at android.os.AsyncTask$2.call(AsyncTask.java:288)
05-14 18:17:04.348: W/System.err(6068): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
05-14 18:17:04.353: W/System.err(6068): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
05-14 18:17:04.353: W/System.err(6068): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
05-14 18:17:04.353: W/System.err(6068): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
05-14 18:17:04.353: W/System.err(6068): at java.lang.Thread.run(Thread.java:818)
有什么问题?
答案 0 :(得分:0)
很奇怪,但我在OnDestroy中有这行代码,经过大量的跟踪和调试后,我发现它导致了这个问题:
if (run != null)
run.cancel(true);
* run是应用程序用来连接服务器的AsyncTask。
我注释掉了2行,app现在连接到服务器没有任何问题。