Connection Resiliency unity example

0 votes
I need an example project or c# code snippet for connection resiliency. Can you please provide a simple example? Thanks
asked May 2, 2016 in Unity by gokhan (20 points)

1 Answer

0 votes
Hi Gokhan,

I am creating a sample to demonstrate connection resiliency. I will share the same with you as soon as possible.

Thanks,

Rajeev
answered May 3, 2016 by rajeev.etc (1,660 points)
Thanks Rajeev. I am waiting.
Hi Rajeev
I am testing connection resiliency while I am waiting your example. This is my code snippet.

public void onConnectDone(ConnectEvent eventObj)
{
    if (eventObj.getResult () == WarpResponseResultCode.SUCCESS)
    {
        connected = true;
        Debug.Log("connected");
        WarpClient.GetInstance().initUDP();
    }
    else if(eventObj.getResult () == WarpResponseResultCode.CONNECTION_ERROR_RECOVERABLE)
    {
        Debug.Log("Recover connection called");
        WarpClient.GetInstance().RecoverConnection();
    }
    else if(eventObj.getResult () == WarpResponseResultCode.SUCCESS_RECOVERED)
    {
        Debug.Log("Recover successeded");
    }
    else
        Debug.Log("Connection error:"+eventObj.getResult());
}

While wifi is open in my phone, I open the application and it prints connected as expected. Then, while still application is open, I close wifi and it enters CONNECTION_ERROR_RECOVERABLE part, then nothing called or happens. Is it normal?. How should I handle this stuation?
Hi Gokhan,

When you call RecoverConnection API and internet is off then you will get CONNECTION_ERROR_RECOVERABLE again. If internet is on then you will get SUCCESS_RECOVERED. If the problem continues then please let me know your Unity version.

The sample script for using connection resiliency can be downloaded from here(https://www.dropbox.com/s/gxxtvwz2psylqnq/Archive.zip?dl=0). You just have to look into the start method of AppWarpManager.cs for following code:
                WarpClient.initialize(apiKey,secretKey);
        listen = GetComponent<MyListener>();
        WarpClient.setRecoveryAllowance (30);
        WarpClient.GetInstance().AddConnectionRequestListener(listen);
and the onConnectDone method of MyListener.cs.

Let me know if you have any queries.

Thanks,
Rajeev
Hi Rajeev
I confirm that when I turn off the internet I get several times CONNECTION_ERROR_RECOVERABLE. When I turn on internet again, nothing happens. I tested using both unity 5.1.1p4 and 5.1.4f1 on different phones. Can you please look at the problem?
Hi Gokhan,

We will test the same with above Unity versions and will update you as soon as possible.

Thanks.
Rajeev
Hi Rajeev
What is new about this topic? Is there a bug or something different? Which unity version are you using for your test?
Hi Gokhan,

Apologies for late reply.

I have tested on Unity versions 5.3.2 and 5.3.3 and it is working fine. The same script i have shared with you in the earlier comments.

Is it possible for you to test the same on these above versions?

Thanks,
Rajeev
Hi Rajeev
I tested on those versions and no change! But What I discovered: If I click turn on/off  wifi button quickly connection resiliency works. I mean I first click turn off then right after that immediately I again turn on it. But if I wait 10-15 second then I turn on it again, it does not work. can you please test it and inform me? I am a bit in a hury...
Hi Gokhan,

We are looking into it and will update you as soon as possible.

Thanks,
Rajeev
Hi Gokhan,

I have tested the issue and please call the recoverConnection from onConnectDone method as follows:

public void onConnectDone(ConnectEvent eventObj){
              
            Debug.Log ("Time:"+System.DateTime.Now);
            Debug.Log ("onConnectDone : " + eventObj.getResult());
            if (eventObj.getResult () == WarpResponseResultCode.SUCCESS)
            {
                Debug.Log("connected");
                //WarpClient.GetInstance().initUDP();
            }
            else if(eventObj.getResult () == WarpResponseResultCode.CONNECTION_ERROR_RECOVERABLE)
            {
                // This method must be called after some delay to avoid continuoes looping
                Debug.Log("CONNECTION_ERROR_RECOVERABLE");
                StartCoroutine ("ExecuteAfterTime");
            }
            else if(eventObj.getResult () == WarpResponseResultCode.SUCCESS_RECOVERED)
            {
                Debug.Log("Recovered successfully");
            }
            else if(eventObj.getResult () == WarpResponseResultCode.AUTH_ERROR)
            {
                Debug.Log("Auth Error");
            }
            else if(eventObj.getResult () == WarpResponseResultCode.BAD_REQUEST)
            {
                Debug.Log("Bad Request");
            }
            else
                Debug.Log("Connection error:"+eventObj.getResult());
}

IEnumerator ExecuteAfterTime()
{
        yield return new WaitForSeconds(3); //Put some delay(in seconds) in calling RecoverConnection say 3,5,10 etc.
            // Code to execute after the delay
        WarpClient.GetInstance().RecoverConnection();
}


Calling RecoverConnection after some time delay will solve this problem. Please use the above code and let me know if problem continues.

Thanks,
Rajeev
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
...