Can Websockets Work On Mobile Phones?
Asked Answered
S

1

11

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?

Shavian answered 15/8, 2014 at 13:13 Comment(1)
I would be interested in seeing an answer for this tooKristofor
V
9

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
     }
    
Violaviolable answered 20/9, 2015 at 23:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.