onConnectDone not getting fired

0 votes
Hi, i have experienced connecting issue when using Appwarp, the onConnectDone callback 
is not always fired, i tried to reproduce the issue by repetitively connect and disconnect 
to appwarp using the code snippet below, here is the logs printed, 

Initialization result 0
Connecting...
onConnectDone: 0
AppWarpTrace :1464683580186:Exception class java.lang.IndexOutOfBoundsException in thread run null
onDisconnectDone: 0
Connecting...
 
As you can see the onConnectDone callback is not fired again after several success attempts and the process is stucked,
no timeout or error noticed, please help.



 

public class ForAppwarpTesting implements ConnectionRequestListener {

private WarpClient _warpInstance;
private String _appKey = API_KEY;
private String _secretKey = SECRET_KEY;

public void init(){
WarpClient.enableTrace(true);
int result = WarpClient.initialize(_appKey, _secretKey);
System.out.println("Initialization result " + result);

try {
_warpInstance = WarpClient.getInstance();
_warpInstance.addConnectionRequestListener(this);

connect();
} catch (Exception e) {
e.printStackTrace();
}


}

private void connect(){
String username = String.valueOf(System.currentTimeMillis());
System.out.println("Connecting...");
_warpInstance.connectWithUserName(username);
}

@Override
public void onConnectDone(ConnectEvent connectEvent) {
System.out.println("onConnectDone: " + connectEvent.getResult());
_warpInstance.disconnect();
}

@Override
public void onDisconnectDone(ConnectEvent connectEvent) {
System.out.println("onDisconnectDone: " + connectEvent.getResult());
connect();
}

@Override
public void onInitUDPDone(byte b) {

}
}

 

closed with the note: Solved
asked May 31, 2016 in Android by siongleng89 (11 points)
closed Jun 2, 2016 by siongleng89

1 Answer

0 votes

Hi Sion,

Please make a check on different Result code you will get in onConnectDone method, Please call disconnect API if its in connected State.Here are the result code you can get

  1. WarpResponseResultCode.SUCCESS
  2. WarpResponseResultCode.AUTH_ERROR
  3. WarpResponseResultCode.CONNECTION_ERROR
  4. WarpResponseResultCode.SUCCESS_RECOVERED
  5. WarpResponseResultCode.BAD_REQUEST
  6. WarpResponseResultCode.CONNECTION_ERROR_RECOVERABLE

if(theClient.getConnectionState()==ConnectionState.CONNECTED)
     warpInstance.disconnect();

I would not like to suggest the same in repeatedly its falls in loop if you are doing it again and again.

Let me know if it helps.

 

Thanks

Vishnu Garg

 

answered Jun 1, 2016 by Vishnu Garg (674 points)
Hi Vishnu,

The code snippet is just for testing purpose, what the problem is now it is really difficult for me to connect to Appwarp, the onConnectDone not getting fired half of the times I tried to connect, and everything was fine up until yesterday, i did update my code snippet and test again, it still end up the same result.


public class ForAppwarpTesting implements ConnectionRequestListener {

    private WarpClient _warpInstance;
    private String _appKey = Terms.WARP_API_KEY();
    private String _secretKey = Terms.WARP_SECRET_KEY();

    public void init(){
        WarpClient.enableTrace(true);
        int result =  WarpClient.initialize(_appKey, _secretKey);
        System.out.println("initialization result " + result);

        try {
            _warpInstance = WarpClient.getInstance();
            _warpInstance.addConnectionRequestListener(this);

            connect();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }


    private void connect(){
        if(_warpInstance.getConnectionState() == ConnectionState.DISCONNECTED) {
            String username = String.valueOf(System.currentTimeMillis());
            System.out.println("Connecting...");
            _warpInstance.connectWithUserName(username);
        }
    }

    private void disconnect(){
        if(_warpInstance.getConnectionState() == ConnectionState.CONNECTED) {
            _warpInstance.disconnect();
        }
    }

    @Override
    public void onConnectDone(ConnectEvent connectEvent) {
        System.out.println("onConnectDone: " + connectEvent.getResult());
        disconnect();
    }

    @Override
    public void onDisconnectDone(ConnectEvent connectEvent) {
        System.out.println("onDisconnectDone: " + connectEvent.getResult());
        connect();
    }

    @Override
    public void onInitUDPDone(byte b) {

    }
}
Please don't use disconnect in onConnectDone method, that may be a reason you are unable to connect.
But the onConnectDone should always getting fired even failed to connect isnt it? How come it doesnt always fire in my case?
I'm facing the same issue. onConnectDone is not getting fired and Connection Status is stuck to "Connecting"
Yes, onConnectDone is always fired, but there are different result code in onConnectDone method its not always success. You need to do validations on that resultcode and do make a disconnect Call
So let me know the result code you are getting and then I will propose a solution it can be a authError or ConnectionErrorRecoverable or may be anything else.
But the problem is onConnectDone is not fired half of the times in my case, how do i give you the result code if onConnectDone is not fired?
And it only starts to happen in the last two days.

I have also seen several similar complains in the forum,
http://forum.shephertz.com/?qa=8958/onconnectdone-and-onleaveroomdone-is-not-getting-called

http://forum.shephertz.com/?qa=8961/warpclient-getinstance-sometimes-connects-sometimes-connecting

so i believe this isn't my issue only.
Even I am checking all the possible cases in onConnectDone method like "authError" or "ConnectionErrorRecoverable", I'm not getting call in any of them. Even if I put a single log in onConnectDone method, it will not print even after one hour of calling connect. Here is my onConnectDone code:

public void onConnectDone (ConnectEvent eventObj)
    {          
        switch (eventObj.getResult ()) {
        case WarpResponseResultCode.SUCCESS:
            Debug.Log ("connection success");
            AppWarpTest.Instance.PostLog ("Connection Successs");
            App42API.SetLoggedInUser (Constants.username);
            App42Push.setApp42PushListener (this);
            #if UNITY_ANDROID
            App42Push.registerForPush (Constants.GoogleProjectNo);
            AppWarpTest.Instance.PostLog (App42Push.getLastPushMessage ());
            #endif
            break;
        case WarpResponseResultCode.AUTH_ERROR:
            AppWarpTest.Instance.PostLog ("Auth Error");
            break;
        case WarpResponseResultCode.BAD_REQUEST:
            AppWarpTest.Instance.PostLog ("Bad Request");
            break;
        case WarpResponseResultCode.CONNECTION_ERR:
            AppWarpTest.Instance.PostLog ("Connection Error");
            break;
        case WarpResponseResultCode.CONNECTION_ERROR_RECOVERABLE:
            AppWarpTest.Instance.PostLog ("Connection Error Recoverable");
            break;
        case WarpResponseResultCode.RESOURCE_MOVED:
            AppWarpTest.Instance.PostLog ("Resource moved");
            break;
        case WarpResponseResultCode.RESOURCE_NOT_FOUND:
            AppWarpTest.Instance.PostLog ("Resource not found");
            break;
        case WarpResponseResultCode.RESULT_SIZE_ERROR:
            AppWarpTest.Instance.PostLog ("Size Error");
            break;
        case WarpResponseResultCode.SUCCESS_RECOVERED:
            AppWarpTest.Instance.PostLog ("Success recoeverd");
            break;
        case WarpResponseResultCode.UNKNOWN_ERROR:
            AppWarpTest.Instance.PostLog ("Unknown Error");
            break;
        case WarpResponseResultCode.USER_PAUSED_ERROR:
            AppWarpTest.Instance.PostLog ("User paused error");
            break;
        default:
            AppWarpTest.Instance.PostLog ("Any error");
            break;
        }
}
Looks like it is finally working now, i will close this thread now
Thanks for the reply, feel free to ask if any further query is concern.
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...