0

I am using okhttp library for network requests and responses.

I am getting java.net.SocketTimeoutException: timeout. I searched on the internet for some possible solution. I read that by disabling the tcp_timestamp on the server side the issue would be resolved.

How can this be done?

Aaron
  • 24,009
  • 2
  • 33
  • 57
Yousaf Iqbal
  • 85
  • 2
  • 10
  • It probably depends on the server, so you should mention which it is and add it as a tag – Aaron Jul 26 '16 at 13:46
  • I am using namecheap.com as hosting server for my files. – Yousaf Iqbal Jul 26 '16 at 13:57
  • Ok, so your http server is probably Apache 2.x. Now this is irrelevant to the tcp_timestamp option, which is set at OS level and which you won't be able to change. However, I should have thought a little bit more about your question first hand : you'd much better configure a larger timeout client-side. – Aaron Jul 26 '16 at 14:08
  • So now it depends on how you retrieve your ressources. If it's via an `HttpUrlConnection`, you can look [that answer](http://stackoverflow.com/a/2799955/1678362). If it's through another method, check it's documentation, it will probably describe a way to change its timeout. – Aaron Jul 26 '16 at 14:09
  • OK i will be back to you after checking your way of doing it. @Aaron – Yousaf Iqbal Jul 26 '16 at 14:15
  • @Aaron i am using okhttp library. setConnectTimeout is not resolved :-( – Yousaf Iqbal Jul 27 '16 at 03:20
  • I'm not knowledgeable with okhttp, but it looks like you can setup a connection builder which has a readTimeout setting. In order of priority you should 1) read their documentation 2) check out their source on github 3) maybe get in touch with their author if all else fails. I've added the okhttp tag to your question so hopefully it will attract people who can answer your question. – Aaron Jul 27 '16 at 12:15

1 Answers1

1

See OkHttp’s recipe on timeouts.

OkHttpClient client = new OkHttpClient.Builder()
    .connectTimeout(10, TimeUnit.SECONDS)
    .writeTimeout(10, TimeUnit.SECONDS)
    .readTimeout(30, TimeUnit.SECONDS)
    .build();
Jesse Wilson
  • 39,078
  • 8
  • 121
  • 128