Indy: closing a connection on servers when all connectiosn closed, and timeouts

Posted on 2004-11-12
Last Modified: 2011-09-20
     Hopefully two not too hard questions. I have the latest stable version of Indy. I am probably just looking at the wrong properties.

1) how do I set timeouts on servers, so that if there is no data flowing, the connection is closed after x amount of time.
2) How do I test to see if there are any live connections to the servers, and if there are not, then stop the server.

ftpserver.Threads.LockList.Count = 0
appears to work well the first time I  check it, but then I set up a timer, then inside the timer I call

if ftps then begin
    if  and (ftpserver.Threads.LockList.Count = 0) then begin //the program dies here
      ftpserver.Active := false;
        ftps := false;
      end else good := false;
    good := false;

I have an antifreeze component on the form, and the problem happens both when I run from within the IDE and externally.

when the program dies, it appears to be running, I can not trace into the line.

Thanks in advance
Question by:Molando
    LVL 4

    Accepted Solution

    Hi Molando,

    1 ) You can define thread's timeouts from the server by assigning some value to the connection's ReadTimeOut property.

    procedure TForm1.IdFTPServer1Connect(AThread: TIdPeerThread);
      AThread.Connection.ReadTimeOut := 10;
    LVL 2

    Author Comment

    As nobody can answer my question about connection counting, assigning all points to answer about timeouts.
    LVL 4

    Expert Comment

    You can know the connection count by yourself. You just need to implement your own connection list. Please take a look at the Indy's "Chat" demo. This is a good example for you to learn what you need to do. Basically, you just need to add a new item to your own list in TIdFTPServer's OnConnect. Then remove it in OnDisconnect. That's all.

    If you don't have Indy demos, you can download it from


    Oktay Sancak
    LVL 2

    Author Comment

    This is what I found out:
      l : Tlist;
      NumberOfConnections : integer;

      l := ftpserver.ActiveThreads.locklist;
      numberofconnections := l.count;

    A bit of an odd way to do things, but no more weird 'freezing' now.

    LVL 4

    Expert Comment

    I'm happy to hear that your problem solved :)

    Featured Post

    Courses: Start Training Online With Pros, Today

    Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

    Join & Write a Comment

    The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
    This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now