小编And*_*rey的帖子

如何重新连接okhttp-ws

如果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)

我收到一个错误 …

java android okhttp

5
推荐指数
1
解决办法
6589
查看次数

标签 统计

android ×1

java ×1

okhttp ×1