I want to post some json string to some URL. I am getting Exception as
Exception: java.net.SocketTimeoutException: failed to connect to
searched lot regarding this issue people are suggesting to increase and decrease timeout parameters in retrofit. I want to know difference between writeTimeout, readTimeout and connectTimeout. So that i can trigger SocketTimeoutException. here my retro client.
public static Retrofit getClient() {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder().writeTimeout(20, TimeUnit.SECONDS).
//.authenticator(new Authen()).
readTimeout(30, TimeUnit.SECONDS).
connectTimeout(20, TimeUnit.SECONDS).
addInterceptor(interceptor).build();
return new Retrofit.Builder()
.baseUrl(DefinesClass.ITS_URL)
// .baseUrl("https://reqres.in")
// .addConverterFactory(GsonConverterFactory.create())
.addConverterFactory(SimpleXmlConverterFactory.create())
.client(client)
.build();
}
Is there any way i can sort that exception help guys?
SocketTimeOut meaning your client is not able to reach the server. Try to test the WebService in Postman.
same for write timeout we failed to write anything in give time.
Difference between all three methods are as below :
connectTimeout :
Sets the default connect timeout for new connections. A value of 0 means no timeout, otherwise values must be between 1 and Integer.MAX_VALUE
when converted to milliseconds.
The connectTimeout
is applied when connecting a TCP socket to the target host. The default value is 10 seconds.
readTimeout :
Sets the default read timeout for new connections. A value of 0 means no timeout, otherwise values must be between 1 and Integer.MAX_VALUE
when converted to milliseconds.
The read timeout is applied to both the TCP socket and for individual read IO operations including on Source of the Response. The default value is 10 seconds.
writeTimeout :
Sets the default write timeout for new connections. A value of 0 means no timeout, otherwise values must be between 1 and Integer.MAX_VALUE
when converted to milliseconds.
The write timeout is applied for individual write IO operations. The default value is 10 seconds.
Source from here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With