Skip to content Skip to sidebar Skip to footer

HTTP FAILED: Java.net.SocketException: Socket Closed Retrofit

tried with multiple ways still facing this issue as I am using RxJava and Retrofit to do all my network operations. Below is my code. <-- HTTP FAILED: java.net.SocketException

Solution 1:

You can Create your OkHttp Client like below, I have faced socket closed exception in the low network, after adding following like in OkhttpClient issue resloved

connectionPool(ConnectionPool(0, 1, TimeUnit.NANOSECONDS))
protocols(listOf(Protocol.HTTP_1_1))

        OkHttpClient.Builder().apply {
        .connectionPool(ConnectionPool(0, 1, TimeUnit.NANOSECONDS))
        .protocols(listOf(Protocol.HTTP_1_1))
        connectTimeout(CONNECT_TIMEOUT, TimeUnit.SECONDS)
        writeTimeout(WRITE_TIMEOUT, TimeUnit.SECONDS)
        readTimeout(READ_TIMEOUT, TimeUnit.SECONDS)
        retryOnConnectionFailure(false)
        }.build()

Post a Comment for "HTTP FAILED: Java.net.SocketException: Socket Closed Retrofit"