Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9121023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:45:53+00:00 2026-06-17T05:45:53+00:00

I have read the article Simple Long Polling Example with JavaScript and jQuery .

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:45:55+00:00Added an answer on June 17, 2026 at 5:45 am

    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:

    <body>
      <div>Server time is: <div class="time"></div></div>'
    </body>
    

    The JavaScript code then send requests to the resource /getdata in a loop (function poll()).

    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.

    program IndyLongPollingDemo;
    
    {$APPTYPE CONSOLE}
    
    uses
      IdHTTPServer, IdCustomHTTPServer, IdContext, IdSocketHandle, IdGlobal,
      SysUtils, Classes;
    
    type
      TMyServer = class(TIdHTTPServer)
      public
        procedure InitComponent; override;
        procedure DoCommandGet(AContext: TIdContext;
          ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo); override;
      end;
    
    procedure Demo;
    var
      Server: TMyServer;
    begin
      Server := TMyServer.Create(nil);
      try
        try
          Server.Active := True;
        except
          on E: Exception do
          begin
            WriteLn(E.ClassName + ' ' + E.Message);
          end;
        end;
        WriteLn('Hit any key to terminate.');
        ReadLn;
      finally
        Server.Free;
      end;
    end;
    
    procedure TMyServer.InitComponent;
    var
      Binding: TIdSocketHandle;
    begin
      inherited;
    
      Bindings.Clear;
      Binding := Bindings.Add;
      Binding.IP := '127.0.0.1';
      Binding.Port := 8080;
    
      KeepAlive := True;
    end;
    
    procedure TMyServer.DoCommandGet(AContext: TIdContext;
      ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
    begin
      AResponseInfo.ContentType := 'text/html';
      AResponseInfo.CharSet := 'UTF-8';
    
      if ARequestInfo.Document = '/' then
      begin
        AResponseInfo.ContentText :=
          '<html>' + #13#10
          + '<head>' + #13#10
          + '<title>Long Poll Example</title>' + #13#10
          + '  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript" charset="utf-8"> ' +
            #13#10
          + '  </script> ' + #13#10
          + '  <script type="text/javascript" charset="utf-8"> ' + #13#10
          + '  $(document).ready(function(){ ' + #13#10
          + '  (function poll(){' + #13#10
          + '  $.ajax({ url: "getdata", success: function(data){' + #13#10
          + '      $("div.time").replaceWith(data);' + #13#10
          + '  }, dataType: "html", complete: poll, timeout: 30000 });' + #13#10
          + '  })();' + #13#10
          + '  });' + #13#10
          + '  </script>' + #13#10
          + '</head>' + #13#10
          + '<body> ' + #13#10
          + '  <div>Server time is: <div class="time"></div></div>' + #13#10
          + '</body>' + #13#10
          + '</html>' + #13#10;
      end
      else
      begin
        Sleep(1000);
        AResponseInfo.ContentText := '<div class="time">'+DateTimeToStr(Now)+'</div>';
      end;
    end;
    
    begin
      Demo;
    end.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A long time ago I have read an article (I believe a blog entry)
I have read this article from High Scalability about Stack Overflow and other large
I have read this article about 400% boost of your website . This is
I am using IMoniker::BindToObject function, and I have read the article on MSDN. The
I have read the MSDN article on MVVM and I am not really convinced.
I have read from some article that say's Apple doesn't approve the application which
I have read from this article http://codahale.com/how-to-safely-store-a-password/ and it says using a salt isn't
First let me say I have read this useful article thoroughly and am using
I have previously read Spolsky's article on character-encoding, as well as this from dive
I have read an article talks about text encoding. It refers that saying that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.