use*_*371 4 java long-polling websocket
I'm writing a backend for a mobile web-app based in Java and I was wondering as far as scalability and ease of use go what are the pros and cons associated with using WebSockets versus Long-Polling solutions like comet. Another option would also be implementing my own solution using TCP. From what I've read it seems that you need to run Long-polling solutions on dedicated servers as they don't run well in Tomcat/Jetty when you start dealing with large numbers of users. WebSockets sounds like it scales better. Are there any disadvantages to going with Websockets over Comet or should I just resort to my own solution using TCP connections? I'm looking for the option that uses the least traffic.
小智 5
我想这取决于你的用例和学习新东西的容忍度,但是,当然,沿着使用WebSocket API进行通信,甚至是SSE的道路,比传统的长轮询/ Comet解决方案更好,原因很多 - 一个你提到过 - 可扩展性,还有带宽利用率和延迟.重要的是要理解WebSocket是Web上的TCP到桌面的东西,例如套接字.在桌面解决方案中,您不必对TCP进行编码,您使用支持传输协议(如STOMP或TCP上的XMPP)的客户端库.使用WebSocket,选择服务器与例如XMPP服务器通信,以及通过WebSockets与服务器通信的XMPP客户端库时,也会这样做.
你可以在这里看到我们的例子,我们有你可以在这里阅读的文档.
需要注意的是HTML5 WebSocket的浏览器采用 - 目前在Chrome和Safari中,很快就会出现在FF和Opera中.我们已经解决了这个问题,但是如果您计划构建自己的服务器,则必须为旧版浏览器创建一个后备解决方案.
| 归档时间: |
|
| 查看次数: |
3550 次 |
| 最近记录: |