Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Timeout for server request made using "Volley" only on Android not iOS

In one of my application, I am sending request to server using volley provided by Google.

Problem : Timeout and error object is null on onErrorResponse(VolleyError error)

What i have tried so far :

1) First I got null error object so solved it by using below code :

 @Override
 protected void deliverResponse(String response) {
    super.deliverResponse(response);
 }

 @Override
 public void deliverError(VolleyError error) {
     super.deliverError(error);
     DebugLog.e("deliverResponse", "getNetworkTimeMs : " + error.getNetworkTimeMs());
 }

So far I have got that there is timeout happening when I got error object null.

2) Now Application is for Android and iOS and web but timeout happens only for Android.

Volley log for requests :

BasicNetwork.logSlowRequests: HTTP response for request

Edited Note :

  1. Web services develoed at server end is same for all three instances (Android , Web and iOS).

  2. Timeout happens when too many users makes requests to the server.

  3. I have set time out to 2 minutes though volley throws timeout in 30 seconds only sometimes.

  4. I have many answers to change server but as it is not possible so any other solution please.

I also like to add that if i can get more information about when timeout can be possible in volley ?

References I have been gone through :

Optimizing Volley

httpclient-often-times-out-using-wifi-is-going-fine-with-3g

long_xmlhttprequest_ajax_requests_timeout_on_android

Edited :

I have also set retry policy as below:

request.setRetryPolicy(new DefaultRetryPolicy(DefaultRetryPolicy.DEFAULT_TIMEOUT_MS * 48,
                0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

And also i do not want to retry if connection timeout.

How can i make efficient service call that can solve problem for timeout.

Any help will be appriciated.

Thanks.

like image 336
AndiGeeky Avatar asked Nov 06 '15 04:11

AndiGeeky


People also ask

What is Volley used for in Android?

Volley is an HTTP library that makes networking for Android apps easier and most importantly, faster. Volley is available on GitHub. Volley offers the following benefits: Automatic scheduling of network requests.

Is Android volley deprecated?

volley (lib) is not deprecated. Why would it be? More importantly, if it works, why does it matter? Deprecated doesn't necessarily mean something is bad.

What is API volley?

Volley is an HTTP library that makes networking very easy and fast, for Android apps. It was developed by Google and introduced during Google I/O 2013. It was developed because there is an absence in Android SDK, of a networking class capable of working without interfering with the user experience.


1 Answers

As i have tried to get solution of this issue for about two months, I did not get any perfect solution. Though I analyze some facts as below :

  1. You can upgrade your server's performance
  2. I have tried making web-service request using HttpURLConnection but still getting same issue over there.

So I think this issue is not specific from volley, but you getting this issue then i would suggest to increase server performance with customizing below RetryPolicy:

int x=2;// retry count
request.setRetryPolicy(new DefaultRetryPolicy(DefaultRetryPolicy.DEFAULT_TIMEOUT_MS * 48,
                    x, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

Hope it will help.

Suggestions are always welcome :)

Please comment below if you found more proper solution.

Thanks.!

like image 92
AndiGeeky Avatar answered Nov 13 '22 03:11

AndiGeeky