如果IP地址更改或连接失败,如何正确重新连接?
我尝试重新连接 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");
}
}
Run Code Online (Sandbox Code Playgroud)
我收到一个错误 …