'Android: Network call made with RxJava and OkHttp SocketTimeoutException
I have a simple API request which I make by using Retrofit/OkHttp.
private fun getNext(
nextId: Long
): Observable<NextData> =
userRepo.getNext(nextId)
.map { it.toDomainObject() }
The API replies 200, OK and it replies fast (definitely less than 3 seconds). However, this call sometimes throws
java.net.SocketTimeoutException: timeout
I also configured my OkHttpClient to have callTimeout(15, TimeUnit.SECONDS). I really do not understand why I have such an exception. Any ideas about solving this problem would be appreciated.
Solution 1:[1]
I don't code in Kotlin but maybe this will help you. I had same problem and this helped me in Java:
client = new OkHttpClient();
client.setConnectTimeout(5, TimeUnit.MINUTES);
client.setReadTimeout(5, TimeUnit.MINUTES);
client.setWriteTimeout(5, TimeUnit.MINUTES);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Marina |
