Longpolling vs Websockets [closed]

别等时光非礼了梦想. 提交于 2019-12-10 13:18:53

问题


I start developing a software, app coded using html + js I need to send this app notification from the server (java code) the app using nginx for routiong and is hosted in AWS. I investigated this subject of real time notification and I get confused between web sockets to long polling In what situations would AJAX long/short polling be preferred over HTML5 WebSockets?

In some articles I read that long polling is an old unlike websocket which is newer and better (In what situations would AJAX long/short polling be preferred over HTML5 WebSockets? ) I start inspect element of gmail facebook whatsapp web pages. I saw that Gmail+ facebook using long polling Unlike whatsapp which using Websocket. So why these companies still choose to use long polling? https://www.quora.com/Does-Facebook-use-WebSockets-for-any-of-their-applications-Are-they-really-useful-at-that-scale-especially-since-they-impose-a-stateful-architecture


回答1:


A couple of reasons why some companies are still using long-polling:

  • WebSocket support is still not 100%, even though the legacy browsers without support are slowly dying out. So if you're a company like Google where products have to work on pretty much every browser out there, you still need a non-WebSocket fallback solution.
  • If you already have a working solution then the costs of moving to WebSocket may well outweigh the savings it brings.



回答2:


WebSockets it's better, it just drains less power, the client does not have to be asking for content every X time, the only downfall it's that old browsers does not support them.

You have a full comparasion in this other question if you want to have more information.

In what situations would AJAX long/short polling be preferred over HTML5 WebSockets?



来源:https://stackoverflow.com/questions/36290520/longpolling-vs-websockets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!