Score:0

Does http protocol standard support long polling?

ua flag

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.

ng flag
It's up to the server's discretion when it wants to kill the connection. So long polling timeout in one application might be different from somewhere else.
BioLogic avatar
ua flag
@oligofren : So how would client know that previous connection was killed and it needs to again establish the connection from scratch?. -- Thanks.
ng flag
When you create a connection you usually also get event handlers associated with the connection. Typically an interface like `connection.on(eventName, eventHandler)` would let the client be informed when the socket closes/is reset, etc. So if the server decides to kill a connection (because it might be a zombie process) to cleanup/preserve resources, the client will know immediately. This is not at the application (HTTP) level, but lower. Look at network sockets: https://en.wikipedia.org/wiki/Network_socket
ng flag
Do note that a connection and a request is two different things. One connection could handle multiple requests over a long period of time. Long polling is not about the connection, but the HTTP requests.
Score:1
us flag

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.

BioLogic avatar
ua flag
Thanks. IS there any API which client can use to know server parameters, for example: if server has implemented long-polling, for how much duration, the server holds the connection on average etc for client to fine tune its parameters for better performance.
us flag
I am not aware of such an API. In the use cases I have seen, it is simply an implicit contract between client and server.
BioLogic avatar
ua flag
Could you please take a look at my another question on this forum. I am new to this forum. Thanks a ton!
ng flag
@BioLogic Remember to accept the answer, if it answers your question.
Score:0
ng flag

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.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.