I'm using Retrofit and OkHttp to connect to server. in most times it works good. but is some case it fail. some times HTTP FAILED: java.net.UnknownHostException and some times java.net.SocketTimeoutException. this error is just when I'm using home wifi to connect to server. but when I use mobile network it is good and there is no problem. using with emulator is good. it happens just with real device. and just some times not all times.
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.readTimeout(30, TimeUnit.SECONDS)
.connectTimeout(30, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)
.build();
retrofit = new Retrofit.Builder()
.baseUrl(ClientConfigs.REST_API_BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.client(httpClient.build())
.build();
compile 'com.squareup.retrofit2:retrofit:2.2.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'