Okhttp3 Is Returning Timeout Exception
I am using okhttp3 as a networking library and Node-mongo as a back-end service.Sometimes when my app starts it shows timeout exception and when I close app and start it again then
Solution 1:
Server timeout will happen if your server is slow or your server's default timeout will be very less.
in this case you can set time-out for your requests like below
client.setConnectTimeout(35, TimeUnit.SECONDS); //change timeout according to your server needs
client.setReadTimeout(35, TimeUnit.SECONDS);
client.setWriteTimeout(35, TimeUnit.SECONDS);
if you are using OkHttp3 then you can use the Builder to achieve this task like below.
client = new OkHttpClient.Builder()
.connectTimeout(30, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.build();
Post a Comment for "Okhttp3 Is Returning Timeout Exception"