📜  长轮询和 WebSocket 的区别

📅  最后修改于: 2021-09-13 01:58:53             🧑  作者: Mango

1.长轮询
除了等待即时响应之外,它是一种技术客户端从服务器请求数据,或者本质上需要向服务器发出 HTTP 请求,然后保持连接打开以使服务器稍后回复。在长轮询的帮助下,服务器允许来自浏览器的大约 6 个并行连接。与其他方式相比,它很方便,并且它是最古老的方法,因此,所有 Web 浏览器都支持它。尽管由于更新较少,它现在不提供重新连接处理。

2. 网络套接字
它是一种 pc 通信协议,允许我们通过单个传输控制协议连接进行全双工通信通道。该协议允许浏览器和网络服务器之间以低权重开销进行交互,从而提供从服务器到服务器的实时数据传输。

长轮询与 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.