I'm currently thinking about creating a soft realtime mobile phone webapp, but when I started researching websockets, I found a load of scare stories about websocket connections dropping out on mobile phones:
WebSockets over a 3G connection
http://blog.hekkers.net/2012/12/09/websockets-and-mobile-network-operators/
Can this still be considered a problem?
Relatedly, I suspect a long polling client might be a good way to implement similar functionality, but wondered about the mobile specific issues I'm likely to encounter.
So far, I've read that long polling requests may have a considerable impact on battery life. I also hear that iOS somehow limits the number of connection made to a single server, which might be a problem.
Have any of you worked on a mobile application with a realtime component? And if you have, what challenges did you encounter, and how did you overcome them?
You can decide to use any WebSocket-based protocol that supports Android. Regardless of your choice, though, you need to consider the entire spectrum of challenges you'll face when it comes to WebSockets.
Avoid using WebSockets if only a small number of messages will be sent or if the messaging is very infrequent. Unless the client must quickly receive or act upon updates, maintaining the open connection may be an unnecessary waste of resources.
Apple has finally added Websockets as first-class citizen to its platforms. Websockets in iOS 13, macOS 10.15, tvOS 13, watchOS 6, and Mac Catalyst have gained first-class citizen status in networking stack. Apple has finally added support in URLSession and for lower level in Network.
I have built several websocket webapps with real-time data, and they perform very well on the iPhone and mobile. Websockets use a ping/pong connection to see if the connection is still alive. Things that have caused disconnection:
Considerations:
Write a simple reconnection routine into the onclose part of your javascript that tries to reconnect after a certain amount of seconds.
function connect(){
websocket = new WebSocket("wss://myws:5020");
websocket.onclose=function(event){
console.log(event);
setTimeout(connect,5000); //re-connect after 5 seconds
//..and so on
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With