2
如何在IP地址更改或連接失敗時進行正確的重新連接?如何重新連接okhttp-ws
我真的試圖讓重新連接okhttp-WS
.....
@Override
public void onFailure(IOException e, okhttp3.Response response) {
try {
connecting();
} catch (Exception e1) {
Timber.e(e1, "onFailure");
}
}
@Override
public void onClose(int code, String reason) {
Timber.d("Connection unexpectedly closed");
connecting();
}
public void connecting() {
if (wsClient == null) {
wsClient = builder.build();
if (call != null) call.cancel();
call = WebSocketCall.create(wsClient, request);
try {
lock.lockInterruptibly();
try { call.enqueue(listener);
} finally {
lock.unlock();
}
} catch (InterruptedException e) {
Timber.e(e, "connecting error");
}
}
,我收到一條錯誤
了java.lang.RuntimeException:無法啓動服務...(具有 演示文稿)}:java.util.concurrent.RejectedExecutionException:任務 [email protected]從 中被拒絕java.util.concurrent.ThreadPoolE xecutor @ d784f8e [終止,池大小 = 0,活動線程= 0,隊列任務= 0,完成的任務= 1] 在 android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3320)