9

What exactly is the difference between long polling and http Keep-Alive?? Doesnt http Keep-Alive solve the issue that long-polling solves??

vivek2k6
  • 119
  • 8

1 Answers1

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.

  • 3
    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. – vivek2k6 Jun 29 '13 at 10:20
  • 4
    No - 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