The network service will retry a connection after 5 seconds in case of socket failure
This commit is contained in:
parent
35570cb4a6
commit
e107c014f0
2 changed files with 14 additions and 2 deletions
|
@ -3,7 +3,9 @@ package cy.agorise.graphenej.api.android;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
import android.os.Looper;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
@ -75,6 +77,9 @@ public class NetworkService extends Service {
|
||||||
|
|
||||||
public static final int NORMAL_CLOSURE_STATUS = 1000;
|
public static final int NORMAL_CLOSURE_STATUS = 1000;
|
||||||
|
|
||||||
|
// Time to wait before retrying a connection attempt
|
||||||
|
private final int DEFAULT_RETRY_DELAY = 5000;
|
||||||
|
|
||||||
public static final String KEY_USERNAME = "key_username";
|
public static final String KEY_USERNAME = "key_username";
|
||||||
|
|
||||||
public static final String KEY_PASSWORD = "key_password";
|
public static final String KEY_PASSWORD = "key_password";
|
||||||
|
@ -572,7 +577,14 @@ public class NetworkService extends Service {
|
||||||
Log.e(TAG,"Giving up on connections");
|
Log.e(TAG,"Giving up on connections");
|
||||||
stopSelf();
|
stopSelf();
|
||||||
}else{
|
}else{
|
||||||
connect();
|
Handler handler = new Handler(Looper.getMainLooper());
|
||||||
|
handler.postDelayed(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Log.d(TAG,"Retrying");
|
||||||
|
connect();
|
||||||
|
}
|
||||||
|
}, DEFAULT_RETRY_DELAY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,7 +19,7 @@ public class SampleApplication extends Application {
|
||||||
int requestedApis = ApiAccess.API_DATABASE | ApiAccess.API_HISTORY | ApiAccess.API_NETWORK_BROADCAST;
|
int requestedApis = ApiAccess.API_DATABASE | ApiAccess.API_HISTORY | ApiAccess.API_NETWORK_BROADCAST;
|
||||||
|
|
||||||
NetworkServiceManager networkManager = new NetworkServiceManager.Builder()
|
NetworkServiceManager networkManager = new NetworkServiceManager.Builder()
|
||||||
.setUserName("nelson")
|
.setUserName("username")
|
||||||
.setPassword("secret")
|
.setPassword("secret")
|
||||||
.setRequestedApis(requestedApis)
|
.setRequestedApis(requestedApis)
|
||||||
.setCustomNodeUrls("wss://eu.nodes.bitshares.ws")
|
.setCustomNodeUrls("wss://eu.nodes.bitshares.ws")
|
||||||
|
|
Loading…
Reference in a new issue