comet的理解

comet:俗称反转Ajax或服务端推数据技术。

1.短轮询(poll):最简单的一种comet,原理是客户端每隔一段固定的时间间隔就向服务器发送请求,建立连接,当从服务器返回后,隔一段固定的时间又重新发送请求。服务器有数据就可以通过这个连接把数据发送过来,没有的话发送空数据。服务器会马上响应,无论有没有数据。

2长轮询(long poll):对短轮询的一个优化方案,人们认为这个才是真正的comet。客户端向服务器发送请求,服务器阻塞该请求线程,并在服务端等待处理,当服务端有结果返回时,服务端立刻把数据发给客户端,并关闭连接。客户端收到数据后,对数据进行处理,并又重新开始一次长轮询。如果没有数据,服务器不会立刻做出响应,会一直等到数据到达服务器或超时,才会响应。

(&引用: The main difference between polling and long polling is how long it takes the server to respond. A long poll generally keeps the connection open for a long time—usually several seconds, but it could be a minute or longer. When an event happens on the server, the response is sent and closed, and the poll immediately begins anew.)

翻译:poll和long poll的主要区别是它会花费服务器多少时间去响应。

3.streaming:好像长连接。服务端向客户端发送数据后,并不关掉连接,而是继续保持该连接一定的时间,当超时或发生错误时才重新开始建立连接。

原文地址:https://www.cnblogs.com/pandaXiong/p/2480592.html