What exactly is the difference between long polling and http Keep-Alive?? Doesnt http Keep-Alive solve the issue that long-polling solves??
Doesnt http Keep-Alive solve the issue that long-polling solves?
Asked Answered
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.
As 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. –
Pesticide
No - HTTP does not work that way. A response is meaningless without a request. –
Lumpy
@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? –
Bibulous
@Bibulous 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. –
Lumpy © 2022 - 2024 — McMap. All rights reserved.