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

  • Home
  • SEARCH
  • 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 362515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:15:13+00:00 2026-05-12T13:15:13+00:00

I use Indy for TCP communication (D2009, Indy 10). After evaluating a client request,

  • 0

I use Indy for TCP communication (D2009, Indy 10).

After evaluating a client request, I want to send the answer to the client. I therefore store the TIdContext, like this (pseudocode)

procedure ConnectionManager.OnIncomingRequest (Context : TIdContext);
begin
  Task := TTask.Create;
  Task.Context := Context;
  ThreadPool.AddTask (Task);
end;

procedure ThreadPool.Execute (Task : TTask);
begin
  // Perform some computation
  Context.Connection.IOHandler.Write ('Response');
end;

But what if the client terminates the connection somewhere between the request and the answer being ready for sending? How can I check if the context is still valid? I tried

if Assigned (Context) and Assigned (Context.Connection) and Context.Connection.Connected then
  Context.Connection.IOHandler.Write ('Response');

but it does not help. In some cases the program just hangs and if I pause execution I can see that the current line is the one with the if conditions.

What happens here? How can I avoid trying to send using dead connections?

  • 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-05-12T13:15:13+00:00Added an answer on May 12, 2026 at 1:15 pm

    Okay, I found a solution. Instead of storing the TIdContext I use the context list provided by TIdTcpServer:

    procedure ThreadPool.Execute (Task : TTask);
    var
      ContextList : TList;
      Context : TIdContext;
      FoundContext : Boolean;
    begin
      // Perform some computation
    
      FoundContext := False;
      ContextList := FIdTCPServer.Contexts.LockList;
      try
        for I := 0 to ContextList.Count-1 do
          begin
          Context := TObject (ContextList [I]) as TIdContext;
          if (Context.Connection.Socket.Binding.PeerIP = Task.ClientInfo.IP) and
             (Context.Connection.Socket.Binding.PeerPort = Task.ClientInfo.Port) then
            begin
            FoundContext := True;
            Break;
            end;
          end;
      finally
        FIdTCPServer.Contexts.UnlockList;
      end;
    
      if not FoundContext then
        Exit;
    
      // Context is a valid connection, send the answer
    
    end;          
    

    That works for me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use Indy's TIdTCPServer (D2009, Indy 10) to communicate with client applications. In the
I use Indy 9 with Delphi 5. In my application I want to communicate
There's a web services I want to call in my application, I can use
I am using HttpCli component form ICS to POST a request. I use an
I used the same request with 2 differents client HTTP. One is accepted by
I have a Delphi application with a Indy TCPServer and TCPClient. I use the
Can i use IdHTTP in the OnExecute Event (Indy) ? like this : procedure
I want to use a temp directory that will be unique to this build.
i use this code in a thread (through Indy Onexecute event) . is there
I'm new to Indy and I want to build a simple proxy-server with it.

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.