I have read the article Simple Long Polling Example with JavaScript and jQuery. The paragraph “Long Polling – An Efficient Server-Push Technique” explains that
the Long Polling technique combines the best-case traditional polling
with persistent remote server connections. The term Long Polling
itself is short for long-held HTTP request.
How can I implement a Indy based HTTP server which uses Long Polling?
Here is a self-contained example project, tested with Indy version 10.5.9 and Delphi 2009.
When the application runs, navigate to
http://127.0.0.1:8080/. The server will then serve a HTML document (hard-coded in the OnCommandGet handler).This document contains a div element which will be used as the container for new data:
The JavaScript code then send requests to the resource
/getdatain a loop (functionpoll()).The server responds with a HTML fragment which contains a new
<div>element with the current server time. The JavaScript code then replaces the old<div>element with the new.To simulate server work, the method waits for one second before returning the data.