strongloop-community / loopback-sdk-android

Android Client SDK for the LoopBack framework.
Other
67 stars 45 forks source link

Increasing the timeout to prevent socket timeout error #90

Open robinskumar73 opened 8 years ago

robinskumar73 commented 8 years ago

I am facing socket timeout exception whenever I am trying to upload a little large image or some file through android. How can I increase timeout to prevent socket timeout exception?

fvumbaca commented 8 years ago

Hi @robinskumar73! I had the same problem.

The cleanest way I found to increase the timeout of the socket was to extend the com.strongloop.android.loopback.RestAdapter class and add the method:

public void setTimeout(int timeoutMillis) {
    getClient().setTimeout(timeoutMillis);
}

What i use is something like:

public class MyRestAdapter extends com.strongloop.android.loopback.RestAdapter{
    public static final int TIMEOUT = 30000;
    public MyRestAdapter(Context context, String url) {
        super(context, url);
        setTimeout(TIMEOUT); // Default to the desired timeout
    }
    // And the method above
}

And finally use this child class in place of the old RestAdapter class.