Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting a timeout in the chat app?

I am working on a chat application where I am using FCM, PHP back-end, and Volley for requests.

Initially, when I log in to my application, chat works fine, and fast, but after sometime volley timeout error start coming up and as I am not using any retry policy, chat message gets lost.

And if I increase socket time out and use retry policy then app gets hung.

Here is my code snippet where I am calling API:

public void doNetworkRequest(int type, String url, final HashMap<String, String> params, Response.Listener requestListener, Response.ErrorListener errorListener) {
        StringRequest mRequest = new StringRequest(type, url, requestListener, errorListener) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                return params;
            }


            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                Map<String, String> headers = new HashMap<String, String>();
                return headers;
            }
        };
//        int socketTimeout = 500000;
//        RetryPolicy policy = new DefaultRetryPolicy(socketTimeout, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
//        mRequest.setRetryPolicy(policy);
        mQueue.add(mRequest);
    }

This issue is coming almost every API sometimes like login, logout, chatting etc.

like image 590
Sangeeta Avatar asked Nov 17 '22 04:11

Sangeeta


1 Answers

try this code

request.setRetryPolicy(new DefaultRetryPolicy(20 * 1000, 1, 1.0f));

this is for Retrying failed requests and customizing request Timeout

like image 56
Syrine Methlouthi Avatar answered Jan 11 '23 04:01

Syrine Methlouthi