Distinguish between writeTimeout,readTimeout and connectTimeout in Retrofit?










0














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 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?










share|improve this question





















  • Timeout of 20 Seconds, is way too bad! Your server is not responding, you should be debugging your server not the increasing timeout at your client. You need to find out the reason why your server is not responding.
    – Abhi
    Nov 12 '18 at 7:15











  • @AbhijithShivaswamy I increased time to 5 to 10 minutes even the same exception i am getting ..but the server guy is telling server is online ..url is working
    – Gaju Kollur
    Nov 12 '18 at 7:20










  • Well, either his server is not responding or you are trying to connect to a wrong end point. 10 minutes of timeout value is crazy! Don't do that!
    – Abhi
    Nov 12 '18 at 9:09















0














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 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?










share|improve this question





















  • Timeout of 20 Seconds, is way too bad! Your server is not responding, you should be debugging your server not the increasing timeout at your client. You need to find out the reason why your server is not responding.
    – Abhi
    Nov 12 '18 at 7:15











  • @AbhijithShivaswamy I increased time to 5 to 10 minutes even the same exception i am getting ..but the server guy is telling server is online ..url is working
    – Gaju Kollur
    Nov 12 '18 at 7:20










  • Well, either his server is not responding or you are trying to connect to a wrong end point. 10 minutes of timeout value is crazy! Don't do that!
    – Abhi
    Nov 12 '18 at 9:09













0












0








0







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 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?










share|improve this question













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 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?







android retrofit retrofit2






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 12 '18 at 7:07









Gaju KollurGaju Kollur

5541721




5541721











  • Timeout of 20 Seconds, is way too bad! Your server is not responding, you should be debugging your server not the increasing timeout at your client. You need to find out the reason why your server is not responding.
    – Abhi
    Nov 12 '18 at 7:15











  • @AbhijithShivaswamy I increased time to 5 to 10 minutes even the same exception i am getting ..but the server guy is telling server is online ..url is working
    – Gaju Kollur
    Nov 12 '18 at 7:20










  • Well, either his server is not responding or you are trying to connect to a wrong end point. 10 minutes of timeout value is crazy! Don't do that!
    – Abhi
    Nov 12 '18 at 9:09
















  • Timeout of 20 Seconds, is way too bad! Your server is not responding, you should be debugging your server not the increasing timeout at your client. You need to find out the reason why your server is not responding.
    – Abhi
    Nov 12 '18 at 7:15











  • @AbhijithShivaswamy I increased time to 5 to 10 minutes even the same exception i am getting ..but the server guy is telling server is online ..url is working
    – Gaju Kollur
    Nov 12 '18 at 7:20










  • Well, either his server is not responding or you are trying to connect to a wrong end point. 10 minutes of timeout value is crazy! Don't do that!
    – Abhi
    Nov 12 '18 at 9:09















Timeout of 20 Seconds, is way too bad! Your server is not responding, you should be debugging your server not the increasing timeout at your client. You need to find out the reason why your server is not responding.
– Abhi
Nov 12 '18 at 7:15





Timeout of 20 Seconds, is way too bad! Your server is not responding, you should be debugging your server not the increasing timeout at your client. You need to find out the reason why your server is not responding.
– Abhi
Nov 12 '18 at 7:15













@AbhijithShivaswamy I increased time to 5 to 10 minutes even the same exception i am getting ..but the server guy is telling server is online ..url is working
– Gaju Kollur
Nov 12 '18 at 7:20




@AbhijithShivaswamy I increased time to 5 to 10 minutes even the same exception i am getting ..but the server guy is telling server is online ..url is working
– Gaju Kollur
Nov 12 '18 at 7:20












Well, either his server is not responding or you are trying to connect to a wrong end point. 10 minutes of timeout value is crazy! Don't do that!
– Abhi
Nov 12 '18 at 9:09




Well, either his server is not responding or you are trying to connect to a wrong end point. 10 minutes of timeout value is crazy! Don't do that!
– Abhi
Nov 12 '18 at 9:09












2 Answers
2






active

oldest

votes


















1














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.






share|improve this answer




























    0














    SocketTimeOut meaning your client is not able to reach the server. Try to test the WebService in Postman.



    • The connect timeout is the time-out applied to create a TCP
      connection to the HTTP server. If the TCP handshake is not completed in this time, the connection attempt failed.

    • The read timeout is the time-out applied from the moment you have
      established a connection (So handshaking is done, and the connection can be used). If no data comes from the server in this time-out time,
      the connection is terminated.

    same for write timeout we failed to write anything in give time.






    share|improve this answer




















      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53257319%2fdistinguish-between-writetimeout-readtimeout-and-connecttimeout-in-retrofit%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      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.






      share|improve this answer

























        1














        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.






        share|improve this answer























          1












          1








          1






          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.






          share|improve this answer












          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 12 '18 at 7:19









          Jeel VankhedeJeel Vankhede

          2,1502217




          2,1502217























              0














              SocketTimeOut meaning your client is not able to reach the server. Try to test the WebService in Postman.



              • The connect timeout is the time-out applied to create a TCP
                connection to the HTTP server. If the TCP handshake is not completed in this time, the connection attempt failed.

              • The read timeout is the time-out applied from the moment you have
                established a connection (So handshaking is done, and the connection can be used). If no data comes from the server in this time-out time,
                the connection is terminated.

              same for write timeout we failed to write anything in give time.






              share|improve this answer

























                0














                SocketTimeOut meaning your client is not able to reach the server. Try to test the WebService in Postman.



                • The connect timeout is the time-out applied to create a TCP
                  connection to the HTTP server. If the TCP handshake is not completed in this time, the connection attempt failed.

                • The read timeout is the time-out applied from the moment you have
                  established a connection (So handshaking is done, and the connection can be used). If no data comes from the server in this time-out time,
                  the connection is terminated.

                same for write timeout we failed to write anything in give time.






                share|improve this answer























                  0












                  0








                  0






                  SocketTimeOut meaning your client is not able to reach the server. Try to test the WebService in Postman.



                  • The connect timeout is the time-out applied to create a TCP
                    connection to the HTTP server. If the TCP handshake is not completed in this time, the connection attempt failed.

                  • The read timeout is the time-out applied from the moment you have
                    established a connection (So handshaking is done, and the connection can be used). If no data comes from the server in this time-out time,
                    the connection is terminated.

                  same for write timeout we failed to write anything in give time.






                  share|improve this answer












                  SocketTimeOut meaning your client is not able to reach the server. Try to test the WebService in Postman.



                  • The connect timeout is the time-out applied to create a TCP
                    connection to the HTTP server. If the TCP handshake is not completed in this time, the connection attempt failed.

                  • The read timeout is the time-out applied from the moment you have
                    established a connection (So handshaking is done, and the connection can be used). If no data comes from the server in this time-out time,
                    the connection is terminated.

                  same for write timeout we failed to write anything in give time.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 12 '18 at 7:19









                  JarvisJarvis

                  64411020




                  64411020



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53257319%2fdistinguish-between-writetimeout-readtimeout-and-connecttimeout-in-retrofit%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Darth Vader #20

                      How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

                      Ondo