0

I recently read about long-polling concept which can be used with http. I want to understand, if any http protocol standard itself supports long-polling concept, so that depending on how client configures the http connection, the server can behave in short-polling manner or long-polling manner, so in effect some clients can connect in short-polling mode and some clients can connect in long-polling mode.

Any sample code esp in java would be helpful.

BioLogic
  • 103
  • 2

2 Answers2

1

Long polling means that the response to request is not sent immediately, only when it is available. HTTP as a protocol has no requirements about the time response generation should take.

The client decides how long it is willing to wait for server's response once it makes a HTTP request.

Similarly, the HTTP server has freedom to send response at any time after HTTP request has been sent.

For example:

Client sends an HTTP request, and waits for response for 5 minutes. If it doesn't receive a response within five minutes, the request times out. In long-polling scenario, client sends another HTTP request and so on.

Respectively on server side, the request processing loop reads the HTTP request and then waits for some entity to generate the response payload, which it then sends back to the client.

Clients cannot control how servers operate. There is no "long-polling requests" as a concrete concept on clients.

There are only HTTP requests, where server decides when to send the answer, and clients who decide how long they are willing to wait.

Tero Kilkanen
  • 38,887
0

There is no such thing as long polling in HTTP. Long polling is a clever (ab)use of HTTP, not a feature of HTTP.

Since HTTP does not know anything of long polling, there cannot be a standard way to check for support.