Restore Session After App is Closed AppWarp WinRT

0 votes
Hello,

Is there anyway to restore or end a session that is still active (using connection resiliency) if the application is closed by the user on Windows Runtime 8.1? As of right now if the user decides to close an app, which kills the current session, but then relaunches the app and connects before the expiration time for the connection resiliency of the previous session has occured it will throw a connect error. Is there anyway to detect this and simply force that session to end, or reconnect again without waiting for the session to expire?

Thanks.
asked Jun 17, 2014 in AppWarp by feraask (45 points)

1 Answer

0 votes
You must call disconenct method while exiting your app. This will cleanly close the session and the user will be able to conenct again with same username.
answered Jun 18, 2014 by Suyash Mohan (900 points)
Okay I have implemented this setup but now I am having a strange issue. In my OnSuspending() event I call disconnect() and then in the Resuming() event I call connect() again. This works fine the first time my app suspends and resumes, but for some reason the second time my app always gets stuck on the Resuming... dialog that Windows Phone shows when resuming an application. If I comment out the connect() call then my app resumes fine. It seems that for some reason something in the connect() call is not resuming properly, any ideas on what might be causing this?

I have even tested this by adding Suspending and Resuming event handlers to the Sample WinRT application provided by ShepHertz and it has the same issue except I have to suspend and resume 3 times. The first time I resume I see at the top "Disconnect Done: 0" where I should see "Connect Done: 0" since I call connect() when I resume, the second time I resume it says "Connect Done: 0" like it should, the third time I get stuck on the windows phone Resuming... dialog. So essentially I run the application, click connect, then suspend the application (using the visual studio lifecyle event tools while debugging or simply hitting the start button when running outside the debugger), then resume, then suspend, then resume, then suspend, then resume and I get stuck on the Resuming dialog.
I've actually noticed now that since v1.6.1 of AppWarp_WinRT even when the application is suspended the connection is being maintained in the background somehow (well not exactly maintained since I do not receive any communication or updates I am just no longer automatically disconnected) as when I resume the application I don't need to reconnect or do anything and I can still use the API calls. Before, when the app was suspended I would resume and get a ConnectionErrorRecoverable response code and I could recover using Connection Resiliency but now I am not getting Connection Resiliency callbacks either so I have no idea how the API's are running in the background as I thought this was not possible on Windows Phone. But if I terminate the app and try to run it again very quickly I will get a login error most likely because my connection has still not expired using the Connection Resiliency API's.

So I am not exactly sure what to do, since Disconnecting() every time I suspend doesn't seem to be working and there is no way to detect when the application is being terminated rather than suspended. Right now when I terminate the application and run it again and connect before the recovery time has passed I get an AUTH_ERROR, is there anyway to force the connection to happen and disconnect the other session when this occurs so I don't have to wait for the recovery time to pass?
Hi,

We are resolving this issue,we will give you update soon.
Hi,

Please find the latest dll from below link
https://github.com/shephertz/AppWarpWinRT/tree/master/v_1.6.2

Although the issue is not completely resolved but the performance is improved ,Please check your game using latest dll and give us feedback.
we will provide next update soon.
I've also noticed that if I have some sort of exception that isn't handled and the app crashes sometimes I can no longer connect as that same user ever again, I keep getting an incorrect session id error when I try to connect. I think it has something to do with the Connection Resiliency staying active and not ever ending the session for that user when there is a crash and so when I try to relaunch the app and connect again with the same user it shows that there is already a session active since it is still trying to recover on the server.

Is there anyway to force a session to end?
Hi,

1. Have you used our latest sdk
https://github.com/shephertz/AppWarpWinRT/tree/master/v_1.6.2

2.Can you please let me know which error code you are getting in OnConnectDone

3.Please check it once after removing connection resiliency ,if the problem still exist or not?
1. Yes I am using v1.6.2

2. I am getting an AUTH_ERROR WarpResponseResultCode

3. I have not tested yet as it is difficult to replicate the error. What I did change is now when the app is suspended I call disconnect() always and then call connect when I resume so that may fix the issue. But is there a way to avoid this disconnect and re-connect cycle? As if the user is in the middle of a game I would like to be able to have the app suspended and resumed without having to re-connect and join and subscribe all over again.
Hi,

Thanks for you reply,

If you are using Connection-Resiliency feature then  recommended way is don't call the disconnect()  on suspension and call RecoverConnection() Api on resume within the connection resiliency  time.It will resume the user on same session.
Hi,

We have found this issue,we will give you update by tomorrow.
Hi

we have added  two new apis to solve this problem
1. GetSessionId()
2. RecoverConnectionWithSessionId

Please follow the below steps.

1.When you get connection success in OnConnectDone,call GetSessionId() api and save the sessionid in your local storage

2.Now whenever application starts whether it is new instance or it is due to crash at last time check your local storage if sessionid exist in your local storage call
RecoverConnectionWithSessioId(<sessionid>,<username>) api. if you are calling it within the connection resiliency time then your last session will be restored otherwise you will get an auth error.    

3.We have also modified connectevent,now you will get reasoncode with the resultcode. right now we have only one reason code WAITING_FOR_PAUSED_USER,

4.Check your reasoncode in autherror of if it is not WAITING_FOR_PAUSED_USER means last session has been expired and you have to call Connect api for new session

5.If user exiting smoothly without a crash,remove sessionid from local storage so next time whenever user start application,it will initiate new session

Find the latest build from below link
https://github.com/shephertz/AppWarpWinRT/tree/master/v_1.6.3

Please let me know if you any problem with this implementation.
Okay I have tried using the newer API and I am still having the same problem. I am calling connect with a username and I am getting an AUTH_ERROR response code and I checked eventObj.getReasonCode() and I am getting a reason code of 0 so I am not sure why. I can't ever connect with this username at all and I have even disabled any sort of connection resiliency. I have not started saving the session ID's yet but without any connection resiliency I should not be getting any error code when I try to connect now even after a crash because the session should be automatically disconnected from the server when the app crashes out right? Or does the server still somehow think there is a session even though the connection is lost?
I dont know why it is happening at your side because its working fine here

Please first try our new apis,I think it will solve your problem

You can also check our sample app from below link
https://www.dropbox.com/s/19b6ywaog94peow/sampleapp.zip

If still your problem exist,we can have a skype call
The issue is not with the new API calls. Those solve the problem fine it seems. But I have certain username's that I was using before the latest updated API was released that I cannot connect to because I do not have the sessionID stored in local storage but I am still getting the AUTH_ERROR every time I try to connect. I even just changed the username in the sample app you provided and I changed the API and Secret keys to my current app and it cannot ever connect with certain usernames because I get an Auth_Error. It seems to me that something on the server is keeping that session alive forever, or at least a very long time (more than a few days) so I cannot ever re-connect with that username.

Is there anyway to simply just end all sessions for a specific username? Can that be added as an API call? Or at least modify getSessionId() where it can take a username and return the sessionID for that user, this way I could recover those sessions that still exist from before I was able to save the session ID locally.
Hi,

Please send me the username and your apikey at "rahul.panchal@shephertz.co.in"
We will check the server side logs to verify if there is a problem.
Hi,

There was some problem at our side,Please now use our latest dll from below link
https://github.com/shephertz/AppWarpWinRT/tree/master/v_1.6.4

If you are still getting AuthError for some usernames,Please send me your username and apikey at "rahul.panchal@shephertz.co.in".We will remove them from our server db.
Okay so far so good, but I have noticed a small typo in the API's. The method to recover a connection with a session id (RecoverConnectionWithSessionId) is spelled incorrectly in the method header/definition, it is missing the last 'n' at the end of the word session. Basically it is showing up for me as RecoverConnectionWithSessioId when I'm assuming it should be RecoverConnectionWithSessionId.
Ok,We will modify it.Thanks for your reply..:)
Hi,
RecoverConnectionWithSessioId  always return 9 in onConnectionDone notification but never successfully recover its connection.

I used the technique explained in this post.
http://blogs.shephertz.com/2014/07/25/appwarp-restore-session-app-crash/
You will get ConnectionErrorRecoverable continuously till your connection is recovered or failed by server.

Suppose your network was lost and you called recoverConnection, you will still get ConnectionErrorRecoverable if there is no network connectivity.

The aim of recoverConnection was to handle network fluctuations or conditions like changing between 2G/3G/Wifi. It can not recover connection if there is no network connectivity.
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
...