2

I am using retrofit and it works fine, but sometimes it does not get the connection and throws an exception of type SocketException, here are the configurations I use:

Version:

       ` 'com.squareup.okhttp3: okhttp: 3.5.0' 
         'com.squareup.retrofit2: retrofit: 2.1.0'`

OkHttpClient with readtimeout, connecttimeout and writetimeout, and Retrofit instance:

`...OkHttpClient okHttpClient = new OkHttpClient.Builder ()
.readTimeout (50, TimeUnit.SECONDS)
.connectTimeout (50, TimeUnit.SECONDS)
.writeTimeout (50, TimeUnit.SECONDS)
Retrofit retrofit = new Retrofit.Builder ()
.baseUrl ("endpoint")
.addConverterFactory (GsonConverterFactory.create ())
.client (okHttpClient) .build ();...`

This configuration I use as singleton pattern.

  • Because sometimes device may lost connection... – Selvin Jan 26 '17 at 01:05
  • Yes, but this is happening frequently and I think that is not normal and could be a problem in my configuration. – David Leonardo Crespín Jan 26 '17 at 01:53
  • Can you post the exception stacktrace, and can you reproduce it against a public URI – Yuri Schimke Jan 26 '17 at 09:12
  • I have same problem, randomly get UnknownHostException, SocketTimeoutException, SocketException, using similar configuration (only timeouts set for 15sek), devices has connected WiFi or Mobile and cannot fix this, write if find working solution – Kenumir Feb 10 '17 at 09:38

0 Answers0