Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
991 views
in Technique[技术] by (71.8m points)

http - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.6k users

...