Recover Connection Issue

0 votes

Hello,

I have implemented "setRecoveryAllowance" after the initialization and "RecoverConnection"  at "WarpResponseResultCode.CONNECTION_ERROR_RECOVERABLE" but still the user doesnt reconnects after getting disconnected.
After getting CONNECTION_ERROR_RECOVERABLE result code in onConnectDone,we have tried to reconnect the device with the internet but we are not getting onConnectDone callback again. We are calling RecoverConnection API after every 5 sec's.

 

Any suggestion would be helpful.

 

Regards:

Vipul

asked May 18, 2016 in Unity by vipulgandhi (11 points)

1 Answer

0 votes
Hi Vipul,

Could you please share the complete code snippets you are using for connection recovery? It will help to debug the problem.

Thanks.
answered May 18, 2016 by rajeev.etc (1,660 points)
Hello Rajeev,

Below is the link to the project.

https://we.tl/9z1BbtsVcg


Regards:
Vipul
I found the code which you have shared on another thread. I found that you are calling recover connection in multiple threads. Please correct the following code:

public void onConnectDone(ConnectEvent eventObj)
        {
//            Debug.Log ("Time:"+System.DateTime.Now);
            Debug.Log ("onConnectDone : " + eventObj.getResult());
            if (eventObj.getResult () == WarpResponseResultCode.SUCCESS)
            {
                WarpClient.GetInstance().SubscribeRoom(appwarp.roomid);
                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("Recover Called");
                Invoke("recoverConnection", 5);
            }
            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());
        }
        //!===============================Added By Vipul========================================
        //===============================Added By Vipul=========================================
        void recoverConnection()
        {
            Log ("RecoverConnection called ");
            WarpClient.GetInstance().RecoverConnection();
            //Invoke("recoverConnection", 5);
        }

In the above code, you are calling invoke function from onConnectDone as well as from the function invoked.
What will happen, for every recoverConnection call there will be a onConnectDone callback. So every onConnctDone callback will call recoverConnection after 5 second as well as schedule another recoverConnection call. which will go in multiple recursion cycle.
I have commented the invoke call in rhe recoverConnection method.
Please try that and let me know if problem continues.

Thanks.
Hello Rajeev,

Thanks for the updates, it is working now.
Hi rajeev, i have tried your code and I am getting this error :

Invoke can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Please help me to solve it
Hi Neel,

You can have a look at this link(https://github.com/PimDeWitte/UnityMainThreadDispatcher). This will help you to call Invoke method from main thread.

I hope this will help you.

Thanks
Rajeev thank you.
It works.
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
...