WebSocket support on mobile devices
Asked Answered
R

2

7

For an Android multiplayer game's communication between players I'm using a WebSocket server and TooTallNate's Java library on the client side to enable WebSocket support in the Android app. So just to point it out clearly, WebSocket support in mobile browsers is not important to me.

Unfortunately, users report that they're experiencing problems such as connection failures or unreceived messages. Is that a general problem of WebSockets on mobile devices (blocked ports, firewalls, mobile Internet connection) or is that probably a flaw in the client side code?

Do you have experience with WebSocket client libraries such as the one above? I've just discovered autobahn.ws for Android - but I don't know if it's worth switching from my current library (see above).

What about WAMP? Is WebSocket technology not exactly the adequate solution so that I should use the sub-protocol (?) WAMP?

Roesch answered 12/1, 2013 at 16:13 Comment(0)
C
5

Every new technology comes with a new set of problems. In the case of WebSocket it is the compatibility with proxy servers which mediate HTTP connections in most company networks. The WebSocket protocol uses the HTTP upgrade system (which is normally used for HTTP/SSL) to "upgrade" an HTTP connection to a WebSocket connection. Some proxy servers do not like this and will drop the connection. Thus, even if a given client uses the WebSocket protocol, it may not be possible to establish a connection.

Candycandyce answered 12/1, 2013 at 23:1 Comment(5)
Thank you! Does that mean that, regardless of the client library that is used and the mobile device (or the carrier), WebSockets will always be doubtful because of proxies? On the other hand, when using mobile data plans, you usually don't have proxies in between, do you?Roesch
for first question. Yes for second question. That depends, usually we do have.Candycandyce
also, can you please share your code for client and server websockets connection and messaging?Candycandyce
On client side, I'm using github.com/TooTallNate/Java-WebSocket and on server-side, I'm using pusher.comRoesch
But how common is this? For example, do a lot of mobile carrier networks behave this way?Zina
V
8

Had these same errors with a bad web socket connection over certain mobile networks. Solved them by:

(1) moving ports: Moving over server and client for websocket over to the SSL port (port 443)

(2) ping keep-alive: Sending periodic "ping" messages from client to server every X seconds, and waiting for a "pong" to return from server. If server doesn't give "pong" back within Y seconds, restart the connection on client.

implementing (1) will get you most of the way there.

Varlet answered 27/10, 2013 at 21:50 Comment(1)
I've found that the ping is pretty important because the current state (as of 2016) of the websocket clients for Android and iOS do not handle idle connection drops in poor coverage very well, or even over wifi in some cases.Antlia
C
5

Every new technology comes with a new set of problems. In the case of WebSocket it is the compatibility with proxy servers which mediate HTTP connections in most company networks. The WebSocket protocol uses the HTTP upgrade system (which is normally used for HTTP/SSL) to "upgrade" an HTTP connection to a WebSocket connection. Some proxy servers do not like this and will drop the connection. Thus, even if a given client uses the WebSocket protocol, it may not be possible to establish a connection.

Candycandyce answered 12/1, 2013 at 23:1 Comment(5)
Thank you! Does that mean that, regardless of the client library that is used and the mobile device (or the carrier), WebSockets will always be doubtful because of proxies? On the other hand, when using mobile data plans, you usually don't have proxies in between, do you?Roesch
for first question. Yes for second question. That depends, usually we do have.Candycandyce
also, can you please share your code for client and server websockets connection and messaging?Candycandyce
On client side, I'm using github.com/TooTallNate/Java-WebSocket and on server-side, I'm using pusher.comRoesch
But how common is this? For example, do a lot of mobile carrier networks behave this way?Zina

© 2022 - 2024 — McMap. All rights reserved.