Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Longpolling vs Websockets [closed]

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

like image 592
Ortal Blumenfeld Lagziel Avatar asked Mar 29 '16 16:03

Ortal Blumenfeld Lagziel


People also ask

Why WebSocket is closed?

The WebSocket is closed before the connection is established error message indicates that some client code, or other mechanism, has closed the websocket connection before the connection was fully established.

Is polling better than WebSocket?

Long polling is more resource intensive on the server than a WebSocket connection. Long polling can come with a latency overhead because it requires several hops between servers and devices.

How do long polling and WebSocket compare?

WebSockets are Full-Duplex meaning both the client and the server can send and receive messages across the channel. Long Polling is Half-Duplex meaning that a new request-response cycle is required each time the client wants to communicate something to the server.

How long does a WebSocket stay open?

A WebSocket times out if no read or write activity occurs and no Ping messages are received within the configured timeout period. The container enforces a 30-second timeout period as the default.


1 Answers

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.
like image 150
gzost Avatar answered Oct 25 '22 08:10

gzost