Problem with DWR and Android-Browser - javascript

I am experiencing a problem with accessing an application from the Android-browser.
The application uses DWR to persist connections to the clients that are connected with it.
Everything works fine for me, except that if the application does not send any data to the client on the Android-phone for 2 minutes, the connection seems to be lost and no data arrive at the client. The same scenario works just fine on Firefox, Opera and Chrome. If the pause between two data transfers is less than 2 minutes, it works just fine.
So, now my question:
Is there some timeout setting for the android browser that I am missing? Or is this some built-in bug/feature/whatever that I cannot circumvent?
I know that I could prevent this from happening with some sort of heartbeat, I would just like to why this is happening.
Thanks in advance, Max
btw: Everything (server, clients) runs on my machine and I am testing this on the android emulator with Windows XP
Android emulator version 1.10 (build_id CUPCAKE-150240)

Could it be that the Android system is garbage collecting your activity and thus loosing your web browser and closing the persistent connection?
Perhaps you could check this by looking in you logcat (on android end) or webserver logs (on remote end)?
if this is the case, you would need to add reconnect code into the onresume/onstart method in android.

Related

How to debug WebSocket / Server Sent Events reconnections on desktop?

I am developing an app that uses Server Sent Events (SSE - basically one-way websockets). If the user uses the site on their mobile chrome browser and then tabs out for about a minute, the SSE connection breaks. If the user then tabs back into the site, it doesn't refresh the page (this is good). But I still need to re-establish the SSE connection so that the server can resume sending messages to them without a refresh.
I'm trying to debug my implementation but having to do it on mobile is very tedious. I have to grab my phone, refresh the page, then tab out, wait 1 minute (so the connection can break), and then tab back in to determine if my code for re-establishing the connection worked properly.
I would much rather be able to debug this on desktop, but I haven't found a way. I have tried the following:
Tried 5 different Chrome extensions for sleeping a tab. Unfortunately, when you navigate back into the tab it just refreshes the page rather than resumes it.
Tried using USB Debugging, but the desktop keeps the tab open at all times even if you tab out on mobile, so the tab never sleeps.
Tried running debugger; in the Chrome Developer Tools console, but even if I let the Javascript sit with its execution frozen for 5+ minutes, it never breaks the SSE connection, so I can't test if reconnecting works.
Tried using an extension to kill the internet for Chrome, but miraculously, this still maintains the active websocket/SSE connections. Apparently Google engineers have deprioritized this effort?
Basically, I am looking to simulate the behavior that happens on mobile when you tab out of your web browser, wait a minute, and then tab back in (the Javascript execution is frozen, the SSE connection is broken after a minute or so, and then tabbing back in resumes Javascript and attempts to reconnect the SSE connection).
Is this possible?
I think that best change you have by emulating your android device. You can do so by installing android studio from https://developer.android.com/studio and then here you have all you need to start and manage your virtual android env https://developer.android.com/studio/run/managing-avds
This it the way I debug my whole mobile development
The most obvious solution to me would be to attach a listener that tracks the events related to tab activation and build some custom solution upon that.
Simply:
window.onfocus = () => {
// Restore SSE session
};
window.onblur = function () {
// Inactive
};
Just for info, SSE is a different protocol from websockets.
In case you are interested in using websockets implementation, I suggest the following library which works very well in my experience: https://www.npmjs.com/package/#stomp/stompjs
Stomp is an abstraction over the websocket protocol, but it also means you would need to implement this on the server side as well.
You can use the chrome://discards to freeze your tab.
You should close and restore the connection based on the Page LifeCycle events.
You Can Try to use pause execution
goto:
Chrome javascript console (Ctrl+Shift+J) > sources > pause script (press f8)
This simulates like a mobile tab switching so you can debug easily
I think this is the simple and easy solution. thanks

Test websocket app on iPhone, Python Flask-SocketIO and Javascript

My app, Python/Flask and vanilla Javascript, is running just fine on my Mac's browsers and I have previously also been able, making sure I'm on the right network, to test my app on Safari on my iPhone 6. I did this by pointing my mobile browser to the IP given by ifconfig on my Mac and correct port. However, after adding Flask-SocketIO, which should allow for Websocket support or atleast long polling, I am no longer able to test my app on my iPhone. All is still fine on Macs browsers but all I get on my iPhone is "Safari could not open the page...".
My app is served over port 5000 but Ive also tried over 80 without any success. I've cleared cache and cookies as well, of course.
Has anyone experienced something similar or have any idea what is going on?
Mobile Safari needs a Content-Security-Policy meta tag. See more at https://developers.google.com/web/fundamentals/security/csp/

What happens when Socket.IO loses focus (for web)

My app works all fine, till the user on mobile (iOS iPad in my case) disconnect due to app change and come back. I have no idea what happens next, if the socket tries to reconnect. I would debug this myself, but I don't have Mac to debug this nor Android (I have WP).
I need the reconnect client to get all the changes that happened between his reconnection and reconnection.
Is there any event called?
Should I call one? When?
I only do care about few browsers: Chrome (desctop, Mac, iOS) and Safary (Mac, iOS)
Site (just for debugging purposes): study.eise.cz

SignalR on mobile web?

I'm evaluating SignalR technology for use in our new product (mobile web application for the broad audience, among other things it needs a real-time chat on some pages).
I've followed the guide to create a very basic chat demo.
Then I deployed the demo on my IIS, and started chatting to myself.
All clients were on the same WiFi network.
Desktop browsers worked more or less OK.
However, Safari on iOS 4.2, and IE on WP7.10 - they both sucked.
Sometimes nothing happened when I pressed the "post" button.
Sometimes outgoing messages were sent OK to the desktop firefox, however there was no incoming messages.
Maybe I'm missing something obvious? Maybe I need jquery mobile instead of the normal one? Maybe I should just tune the IIS/web.config/whatever, and the SignalR will flourish and start to work flawlessly even through the crappy mobile internet?
Or does it mean that since it doesn't work even while on WiFi within a single hop from the web server, I should throw SignalR away and just write some JavaScript to poll a JSON endpoint for new messages?
Thanks in advance!
I have been developing an app with phonegap (that means that uses the Safari browser) and SignalR for Android and IPhone. The major issue I had was with iOS 6.x because SignalR did not connect with default config. I have found a workaround for that and I had explained it here. Let me know if you find it useful.
This code will simulate a connect, check for messages, disconnect and wait 5 secs to solve the iOS issue.
In js add
$.connection.hub.start({ transport: 'longPolling' }).done(function (myHubConnection) { });
and in Application_Start() add
GlobalHost.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(1);
Microsoft.AspNet.SignalR.Transports.LongPollingTransport.LongPollDelay = 5000;
RouteTable.Routes.MapHubs();
Not all mobile browsers (e.g. android, opera mini) support websockets. You'll find a nice chart of supporting browsers at http://www.hanselman.com/blog/YourUsersDontCareIfYouUseWebSockets.aspx

android can't see web service

I've written my first Android app (Sencha Touch + Phonegap using Eclipse on PC). It pulls some JSON from a WCF service. It works fine in the emulator.
I've now put it on my phone (Samsung GT-19100T running Gingerbread). The app runs but hangs when calling the service. The phone just shows the loading animation. The server shows no request has reached it. The phone can browse the net ok.
EDIT: I should add that the problem is not the server. I can browse to the same services ok on PC, and we have an iPhone app that works with it fine.
The only other strange thing I've noticed is that if I browse to the endpoint on iPhone or PC, I get the JSON text in the browser. If I try it on the android's browser it says "cannot download".
How do I go about diagnosing this?
Is there some sort of option on the phone?
found it. The answer is to SHOOT ME NOW.
the URL had been entered so long ago I forgot all about it, including little details like the fact that it used an internal ip address.
Total facepalm. No, that won't do it. Let's try a facedesk...

Categories