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 7054019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:34:31+00:00 2026-05-28T03:34:31+00:00

I am using TIdTCPClient to get a file list all works well but when

  • 0

I am using TIdTCPClient to get a file list all works well but when i close the client application and open it again i don’t receive any event on TCPServer onExecute though the TIdTCPClient successfully connects to it and i am not able to send the file list.

What am i doing wrong ?

Some code :

procedure TTaifun.csConnected(Sender: TObject);
begin
  cs.IOHandler.WriteLn('FILE_LIST|NOW'); //Sending a request to server for the files
  fname := cs.IOHandler.ReadLn(nil); //Got the file names
  files := ExplodeString(fname,'|'); // Parse the files
end;

procedure TTaifun.svExecute(AContext: TIdContext);
var
  cmds, flist: TStringList;
  i: Integer;
  tmp: string;
  FS : TFileStream;
begin
  CSection.Enter; //Enter critical section
  cmds := ExplodeString(AContext.Connection.IOHandler.ReadLn(nil), '|'); 
  try
    if cmds[0] = 'FILE_LIST' then //Check command received
    begin
      flist := TStringList.Create;
      flist.LoadFromFile(MyPath + 'files.dat');
      tmp := '';
      for i := 0 to flist.Count - 1 do
      begin
          tmp := tmp + flist[i] + ',' + GetFileSize(flist[i]) + ',' +
          BoolToStr(FileExists(MyPath + 'Thumbs\' +
          ChangeFileExt(ExtractFileName(flist[i]), '.thb')),true) + '|'; //Do some parsing
      end;
      AContext.Connection.IOHandler.WriteLn(tmp); //Send the string
    end
 finally
  CSection.Leave; //Leave critical section
 end;
end;
  • 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-28T03:34:31+00:00Added an answer on May 28, 2026 at 3:34 am

    You are not protecting your critical section from exceptions. When the client disconnects, an exception will be raised by either ReadLn() or WriteLn() (depending on timing) to terminate the thread for that client. The next time the OnExecute event is called for a different thread, the critical section will still be locked and cannot be re-entered again, deadlocking your code. Add a try/finally to your code to guard against that, eg:

    procedure TTaifun.svExecute(AContext: TIdContext); 
    var 
      ...
    begin 
      CSection.Enter; //Enter critical section 
      try
        ...
      finally
        CSection.Leave; //Leave critical section 
      end;
    end; 
    

    With that said, why are you using a critical section to begin with? The code you showed is thread-safe by itself, it does not need to be protected from concurrent access:

    procedure TTaifun.svExecute(AContext: TIdContext);     
    var     
      cmds, flist: TStringList;     
      i: Integer;     
      tmp: string;     
    begin     
      cmds := ExplodeString(AContext.Connection.IOHandler.ReadLn, '|');      
      if cmds[0] = 'FILE_LIST' then //Check command received     
      begin     
        tmp := '';     
        flist := TStringList.Create;     
        try
          flist.LoadFromFile(MyPath + 'files.dat');     
          for i := 0 to flist.Count - 1 do     
          begin     
            tmp := tmp + flist[i] + ',' + GetFileSize(flist[i]) + ',' +     
              BoolToStr(FileExists(MyPath + 'Thumbs\' +     
              ChangeFileExt(ExtractFileName(flist[i]), '.thb')),true) + '|'; //Do some parsing     
          end;
        finally
          flist.Free;
        end;     
        AContext.Connection.IOHandler.WriteLn(tmp); //Send the string     
      end;
    end;
    

    Alternatively:

    procedure TTaifun.svExecute(AContext: TIdContext);     
    var     
      cmds, flist: TStringList;     
      i: Integer;     
    begin     
      cmds := ExplodeString(AContext.Connection.IOHandler.ReadLn, '|');      
      if cmds[0] = 'FILE_LIST' then //Check command received     
      begin     
        flist := TStringList.Create;     
        try
          flist.LoadFromFile(MyPath + 'files.dat');     
          for i := 0 to flist.Count - 1 do     
          begin     
            flist[i] := flist[i] + ',' + GetFileSize(flist[i]) + ',' +     
              BoolToStr(FileExists(MyPath + 'Thumbs\' +     
              ChangeFileExt(ExtractFileName(flist[i]), '.thb')),true); //Do some parsing     
          end;
          flist.Delimiter := '|';
          flist.StrictDelimiter := True;
          AContext.Connection.IOHandler.WriteLn(flist.DelimitedText); //Send the string     
        finally
          flist.Free;
        end;     
      end;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the C# Facebook SDK 5.0.3 everything works fine whit the client.Get(/me). But when
I have a client/server application written in delphiXe2 using Indy TIdTCPServer and TIdTCPClient that
I'm using Indy10 under Delphi2009. I have a server/client application, with TidTCPServer and TidTCPClient.
Using the HTML5 File API I can get the Binary String representation of a
using file_get_contents , I open an Internet URL and get the contents of this
Using Play 2.0.1 I defined the following route: GET /demo/list controllers.Demos.listDemos(page: Int ?= 0,
Using of mobile dialog authentication is working well for other mobile devices except on
Using the navigator.geolocation object in JavaScript. Trying to establish accurate ranges, but wondering exactly
Using Android TelephonyManager an application can obtain the state of data activity over the
using a binary search tree I need to add to a vector all int

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.