Link to home
Start Free TrialLog in
Avatar of Molando
Molando

asked on

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

Hello,
     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
  try
    if ftpserver.active  and (ftpserver.Threads.LockList.Count = 0) then begin //the program dies here
      ftpserver.Active := false;
        ftps := false;
      end else good := false;
  except
    good := false;
  end;
  end;

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
                  Molando.
ASKER CERTIFIED SOLUTION
Avatar of ceoworks
ceoworks

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Molando
Molando

ASKER

As nobody can answer my question about connection counting, assigning all points to answer about timeouts.
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 http://www.projectindy.org/DemoDownloads/Indy9Demos_26Oct04.zip

Regards,

Oktay Sancak
Avatar of Molando

ASKER

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

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

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

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