Open In App

Difference between Long Polling and WebSocket

Improve
Improve
Like Article
Like
Save
Share
Report

1. Long Polling :
It is a technology client requests for data from the server besides waiting for an instant response or essentially entails making an HTTP request to a server and then maintaining the connection open to enable the server to reply later. With the help of long polling the server permits about 6 parallel connections from the browser. It is convenient in contrast to other ways, and it is the oldest method and for this reason, is supported on all web browsers. Though due to the fewer updates in this it does now not furnish re-connection handling.

Advantages-

  1. Little or no support at all needed for fallback layers.
  2. It has a short waiting period.
  3. It is easy to implement.

Disadvantages-

  1. Latency issues are there.
  2. It does not offer resource utilization.
  3. During the process, there are several kinds of delays.

2. WebSocket :
It is a pc communication protocol that permits us full-duplex communication channels over a single transfer control protocol connection. This protocol permits an interplay between a browser and web server with low weight overheads and thus offering real-time data transfer from and to the server.

Advantages-

  1. Allows two-way communication.
  2. Compatibility between platforms 
  3. Allows to send and receive data much faster than HTTP.

Disadvantages-

  1. Does not provide edge caching.
  2. Non-availability of AJAX-like success mechanisms.
  3. Web browser must be fully HTML5 compliant.

Difference Between Long Polling vs WebSocket :

S. No. Long Polling WebSocket
1. It offers a unidirectional communication channel. It offers a bidirectional communication channel.
2. There is an issue of resource wastage. There is no such issue of resource wastage. 
3. It has a short waiting period. It has a long waiting period.
4. It does not offer resource utilization.  It offers resource utilization.
5. There are not many complications while enabling a connection process. There are different complications while enabling a connection process.
6. In this, there are several kinds of delays during the process. In this, there are no delays during the process.
7. It uses AJAX to communicate properly. It does not use AJAX to communicate over the network.
8. It uses HTTP protocol for connection. It uses TCP/IP protocol for connection.
9. It is easy to implement. It is difficult to implement when compared with Long Polling.
10. Latency problems are there. There are no latency problems.
11. Delay can occur since client always have to make new request after receiving data Provides real time updates
12.  Poor scalability since new request has been sent each time Highly Scalable due to persistence connection

 


Last Updated : 20 Apr, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads