okhttp: Socket send timeout

Hi, i have created a socket connection inside a service using:

    OkHttpClient client = new OkHttpClient.Builder()
                    .readTimeout(3000,  TimeUnit.MILLISECONDS)
                    .writeTimeout(3000,  TimeUnit.MILLISECONDS)
                    .connectTimeout(3000,  TimeUnit.MILLISECONDS)
                    .build();

            Request request = new Request.Builder().addHeader(Config.WEBSOCKET_PARAM_COOKIE, "access_token=" + userToken)
                    .url(mySocketUrl)
                    .build();
            webSocket = client.newWebSocket(request, websocketListener);

Everything works fine, but now i’m trying to simulate a no connection scenario. I have turned on the airplane mode, while in a chat, and tryied to send a message using .send(String). I through that it would fire some kind of exception or the onFailure/onClosed methods, but none of them are called. How can i detect if the .send function really worked? Thanks in advance.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 5
  • Comments: 18 (8 by maintainers)

Most upvoted comments

Got stuck on this for awhile. Turns out some Emulator seems to have a problem with onFailure method.

@zafrani try OkHttp 3.10.