简体   繁体   English

移动设备上的WebSocket支持

[英]WebSocket support on mobile devices

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. 对于Android多人游戏的玩家之间的通信,我在客户端使用WebSocket服务器和TooTallNate的Java库 ,以在Android应用程序中启用WebSocket支持。 So just to point it out clearly, WebSocket support in mobile browsers is not important to me. 所以只是要明确指出,移动浏览器中的WebSocket支持对我来说并不重要。

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? 这是移动设备上WebSockets的一般问题(阻塞端口,防火墙,移动互联网连接)还是客户端代码中的一个缺陷?

Do you have experience with WebSocket client libraries such as the one above? 您是否具有WebSocket客户端库的经验,例如上面的那个? I've just discovered autobahn.ws for Android - but I don't know if it's worth switching from my current library (see above). 我刚刚发现了适用于Android的autobahn.ws - 但我不知道是否值得从我当前的库中切换(见上文)。

What about WAMP? WAMP怎么样? Is WebSocket technology not exactly the adequate solution so that I should use the sub-protocol (?) WAMP? WebSocket技术不是完全正确的解决方案,因此我应该使用子协议(?)WAMP?

Had these same errors with a bad web socket connection over certain mobile networks. 在某些移动网络上发生了与错误的Web套接字连接相同的错误。 Solved them by: 解决了他们:

(1) moving ports: Moving over server and client for websocket over to the SSL port (port 443) (1)移动端口:通过服务器和客户端移动websocket到SSL端口(端口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. (2)ping keep-alive:每隔X秒从客户端向服务器发送定期“ping”消息,等待“pong”从服务器返回。 If server doesn't give "pong" back within Y seconds, restart the connection on client. 如果服务器在Y秒内没有返回“pong”,请在客户端重新启动连接。

implementing (1) will get you most of the way there. 实施(1)将为您提供大部分的帮助。

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. 在WebSocket的情况下,它与代理服务器的兼容性在大多数公司网络中调解HTTP连接。 The WebSocket protocol uses the HTTP upgrade system (which is normally used for HTTP/SSL) to "upgrade" an HTTP connection to a WebSocket connection. WebSocket协议使用HTTP升级系统(通常用于HTTP / SSL)将HTTP连接“升级”到WebSocket连接。 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. 因此,即使给定客户端使用WebSocket协议,也可能无法建立连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM