10

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?

Community
  • 1
  • 1
Charlie
  • 4,197
  • 5
  • 42
  • 59

1 Answers1

7

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:

  • If you close down the app, then the connection will be dropped (on iOS webapps).
  • If the network does go down (wifi/3g/4g), then the connection will be dropped and not recover anything that was sent in that dropped time.

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
     }
    
Dan Swain
  • 2,910
  • 1
  • 16
  • 36
Entrabiter
  • 752
  • 7
  • 13