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?

caw
  • 30,999
  • 61
  • 181
  • 291

2 Answers2

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.

Philip Fung
  • 375
  • 6
  • 5
  • 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. – Nick Jul 01 '17 at 14:46
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.

atta
  • 166
  • 1
  • 1
  • 10
  • 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? – caw Jan 13 '13 at 02:15
  • for first question. Yes for second question. That depends, usually we do have. – atta Jan 13 '13 at 03:04
  • also, can you please share your code for client and server websockets connection and messaging? – atta Jan 13 '13 at 03:06
  • On client side, I'm using https://github.com/TooTallNate/Java-WebSocket and on server-side, I'm using http://pusher.com/ – caw Jan 13 '13 at 03:09
  • 1
    But how common is this? For example, do a lot of mobile carrier networks behave this way? – Kevin Krumwiede Oct 03 '14 at 22:46