What exactly is the difference between long polling and http Keep-Alive?? Doesnt http Keep-Alive solve the issue that long-polling solves??
Asked
Active
Viewed 1,914 times
1 Answers
13
No. They're almost completely unrelated.
HTTP keepalive allows the client to keep a connection open, but idle, to allow it to make future requests a little bit more efficiently. The server cannot send data to a client over a keepalive connection, as no request is active.
Long polling is a mechanism where the server keeps a request (and thus a connection) active, but not sending data, to allow the server to send data to the client when it becomes available -- for instance, when an event occurs.
-
3As http keepalive keeps the connection open, can't server push the data, as soon as it has, independent of whether it has got any request or not. – vivek2k6 Jun 29 '13 at 10:20
-
4No - HTTP does not work that way. A response is meaningless without a request. – Jun 29 '13 at 15:31
-
@duskwuff Is there any point to set the Keep-alive header when using Long Polling? For example, if the server sends out some data to the client every 5 seconds using Long Polling, do I need to set the Keep-alive header? Or is it unnecessary? – JuliusvM May 12 '18 at 22:04
-
@JuliusvM No. It may actually be harmful. `Keep-Alive` controls behavior when the request ends -- but a long polling request will take a very long time to end. – May 12 '18 at 22:10