AppWarp onConnectDone called many times on WinRT

0 votes

Hello,

I am developing an Application for Windows Phone and Windows 8.1 using the Windows Runtime using the AppWarp SDK and App42 Cloud SDK and for some reason after I make my initial connect call in AppWarp and receive my onConnectDone successfully after a short period of time I get another call to onConnectDone with an error code. What I basically have set up is the following scenario:

  1. The user opens the app to the LoginPage.xaml with fields for username and password and the app sets up my App42 Services
  2. The user enters the username and password and hits Login
  3. This calls my App42 Authenticate() with the given username and password and an instance of the LoginPage
  4. The Authenticate Callback is then called and if it is successful I call the App42 GetSession() with the same instance of the LoginPage
  5. When the GetSession() callback is received successfully I then move to the next page LoginPage.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>. {Frame.Navigate(typeof(MainPage))});
  6. In the NavigationHelper_LoadState of MainPage I check if my warpClient is null and initialize it and GetInstance() and then setup all the required Listeners and then call Connect()
  7. I get the OnConnectDone callback successfully and then from this callback I call the App42 GetAllFriends() and App42 GetFriendRequest()
  8. I get the GetAllFriends callback successfully and from this callback I call GetSession(false) for every friend in the List<Buddy> response to check if they are currently online.
  9. When I get the GetFriendRequest callback successfully I return and do nothing.

The problem is between 6 and 9 my code keeps calling the OnConnectDone() many times (I've set a breakpoint on this function while debugging to check) and I end up with an warpClient that no longer has a valid connection for some reason. I am not sure what is going on but I believe it has something to do with strange threading behavior that I am unaware of. I've set a breakpoing on the warpClient.Connect() call and it is only run once so I really can't figure out what is going on. Any ideas?

UPDATE: Okay so I have commented out everything after step 6 and have it set so the LoginPage does nothing but simply call Frame.Navigate(typeof(MainPage)) when a button is clicked and I put breakpoints on every class and method and function call and the warpClient.connect() is only called once like it is supposed to when the page is loaded but I am getting two callbacks to OnConnectDone() and the second time has a result code of 6 which is supposed to be a network error. I really have no idea what is happening.

I know the AppWarp WinRT SDK was just released so is this possibly a bug?

UPDATE 2: Okay looking at the call stack when the 2nd onConnectDone is called I see a lot of references to keep alive timer expiring. Am I required to set a keep alive timer to a value every time I connect to AppWarp? I thought this was only required to recover dropped connections, does this mean my connection is dropping?

UPDATE 3: Okay so it seems that for some reason my connection keeps failing and the onConnectDone is trying to recover the connection so I set up a recovery allowance of 2 minutes and I handle the recoverable connection response code in my onConnectDone() but my connection just keeps on dropping and then I recover over and over. My internet connection is fine and all the internet functions are still working on my device. Any ideas what is happening?

I've also noticed that the connction quite frequently drops when I interact with the screen in some way.

asked May 3, 2014 in AppWarp by feraask (45 points)
edited May 3, 2014 by feraask

1 Answer

0 votes
Hi,

Its working fine in our sample app,We have uploaded the sample app,Please find it from below link

https://github.com/rahulpshephertz/WinRTSample
answered May 5, 2014 by errahulpanchal (169 points)
I have tried running the sample as well. I put in my API and Secret key and I set a breakpoint in MainPage.xaml.cs:47 at the line switch(tag) and also a breakpoint on the onConnectDone callback (ConnectionListen.cs:24). Then I run it and hit connect,  it reaches the first breakpoint in the MainPage.xaml.cs and from there I step through until I hit the second breakpoint in onConnectDone and I hit continue. It goes through the first time just fine, it connects and I get the callback with result 0 (SUCCESS). But then after a second or two the onConnectDone callback is called again with result 6. I am having similar behavior in my app as well. This only seems to happen when I am debugging.

Looking at the call stack I see:
>    WinStoreApp42SampleApp.exe!WinStoreApp42SampleApp.ConnectionListen.onConnectDone(com.shephertz.app42.gaming.multiplayer.client.events.ConnectEvent eventObj) Line 23    C#

APPWARP_WINRT.DLL!com.shephertz.app42.gaming.multiplayer.client.WarpClient.fireConnectEvent(byte code)    Unknown
     APPWARP_WINRT.DLL!com.shephertz.app42.gaming.multiplayer.client.WarpClient.OnConnect(bool success)    Unknown
     APPWARP_WINRT.DLL!com.shephertz.app42.gaming.multiplayer.client.ClientChannel.Send()    Unknown
     mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start<com.shephertz.app42.gaming.multiplayer.client.ClientChannel.Send>(ref com.shephertz.app42.gaming.multiplayer.client.ClientChannel.Send stateMachine)    Unknown
     mscorlib.dll!System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start<com.shephertz.app42.gaming.multiplayer.client.ClientChannel.Send>(ref com.shephertz.app42.gaming.multiplayer.client.ClientChannel.Send stateMachine)    Unknown
     APPWARP_WINRT.DLL!com.shephertz.app42.gaming.multiplayer.client.ClientChannel.Send(com.shephertz.app42.gaming.multiplayer.client.message.WarpRequestMessage msg, byte[] data, long length)    Unknown
     APPWARP_WINRT.DLL!com.shephertz.app42.gaming.multiplayer.client.ClientChannel.SendRequest(com.shephertz.app42.gaming.multiplayer.client.message.WarpRequestMessage msg)    Unknown
     APPWARP_WINRT.DLL!com.shephertz.app42.gaming.multiplayer.client.ClientChannel.keepAliveTimerExpired(object source)    Unknown

and then 7 mscorlib.dll calls relating to TimerQueue and Timer Callbacks.
Also when I attempt to send updates a lot of the times I simply get the network error response code.

I am only experiencing these issues when testing on windows phone 8.1 on my actual device (Nokia Lumia 1020 and 920) and sometimes it does work fine. When I use the Windows Phone 8.1  emulator on my computer it seems to work as it should although if I set breakpoints in certain areas of the code it does still fail.

What is very strange is that if I setup a button which does the exact same thing as the LoadState event of the page (literally I call the button_click function when I am loading the page which sends data to other users) the sendPrivateUpdate in LoadState will fail but when I use the button it always seems to work. Is it possible that trying to use both AppWarp and App42 at the same time is causing issues? All my App42 API calls and callbacks are set up the exact same way as my AppWarp ones but the App42 ones all work fine
Hi,

Please don't put the breakpoint in onConnectDone,It stops the execution of background thread.if you want to debug just put the code to write on console or on UI . In Sample app i have already written the code to print on UI,You don't need to do anything
Okay that's fine but I just can't figure out what is going on. When I open my app in the constructor for the first page I initialize and setup my WarpClient just as the sample does and then when the user enters their name and hits login I simply connect but then when I try to sendPrivateUpdate right after the login (in the same function call, i.e. when the login button is clicked it both connects and sends an update) it always fails. What I do when the login button is clicked I call connect and then while(connectDone == false) ; I loop until I get the onConnectDone callback which sets the global variable connectDone = true and then I try to send the updates right after but for some reason I always get a network error but I can immediately press a button that calls the exact same sendPrivateUpdate code and it works. Do you have any idea what may be going on?
It is hard to say whats going wrong but it is not recommended way. You should write sendPrivateUpdate in onConnectDone.
 
public void onConnectDone(ConnectEvent eventObj)
 {
   if((eventObj.getResult()==WarpResponseResultCode.SUCCESS)&&sendPrivateflag)
       {
    WarpClient.GetInstance().sendPrivateUpdate("username", Encoding.UTF8.GetBytes("Private update"));
       }
 }

and in login_click

void loginclick(object sender, RoutedEventArgs e)
{
 WarpClient.GetInstance().Connect("username");
 sendPrivateflag=true;
}
Thank you so much for the help. I'm sorry I've been posting so much I've just been having such strange issues everywhere and it's really frustrating as I'm using the App42 SDK in the same manner and everything works perfeclty.

In any case, I did a setup like the above post and it works but only if I don't follow the connect call with a call to an App42 function. I tried the above setup like this:

public void onConnectDone(ConnectEvent eventObj)
 {
   if((eventObj.getResult()==WarpResponseResultCode.SUCCESS)&&sendPrivateflag)
       {
    WarpClient.GetInstance().sendPrivateUpdate("username", Encoding.UTF8.GetBytes("Private update"));
       }
 }

public class Callback : App42Callback
{
    public void onSuccess(object response)
    {
        GlobalContext.authenticateComplete = true;
    }

    public void onException(App42Exception exception)
    {}

}

and in login_click

void loginclick(object sender, RoutedEventArgs e)
{
 sendPrivateflag=true;
 WarpClient.GetInstance().Connect("username");

 /*** App42 Call ***/
 GlobalContext.authenticateComplete = false;
 userService.Authenticate("username", "password", new Callback());
 await Task.Run( () => { while (GlobalContext.authenticateComplete = false) ; });

 Frame.Navigate(typeof(PageTwo));
}

and it didn't work. But when I commented out the App42 calls and the wait right after calling connect it works fine. If I reorder the calls and do the App42 stuff first it also works.

Do you have any idea why this might be happening? It's not a huge issue since I was able to just reorder things but it is strange and it's been driving me crazy lately trying to figure out what is happening.
await Task.Run( () => { while (GlobalContext.authenticateComplete = false) ; });

Perhaps you've missed a '=' , maybe you meant to do '==' in the above statement.


The way you are structuring it seems incorrect. On WP, all network communication is designed to be Async. And so are the App42 and AppWarp SDKs.
By adding code such as

 await Task.Run( () => { while (GlobalContext.authenticateComplete = false) ; });

It seems you are trying to enforce a synchronous pattern in your app when you are making network calls to the SDK.
Okay so I am having a similar issue now even with the sample app. All I did was add an dummy button which does nothing on the MainPage.xaml and after I connect if I press the button very rapidly my AppWarp connection disconnects with result 6. So literally I open the app, press connect, then after the textblock at the top says connect done: 0 then I start pressing the dummy button I created very rapidly and within a short period of time I will see connect done: 6 at the top.

It seems that for some reason when the UI is having interactions the AppWarp connection is dropped. Perhaps the background thread is just not running enough to maintain the connection, I'm not sure.

I have tested this on both Windows 8.1 and Windows Phone 8.1 using the AppWarp WinRT SDK in the sample app provided and creating a copy of the same project where I added a Windows Phone 8.1 solution to make the sample app a universal app. I have also found this same issue in my own application which disconnects sometimes when nothing is happening on screen at all but mostly when there is some sort of UI interaction.
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
...