?
Solved

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

Posted on 2004-11-12
5
Medium Priority
?
342 Views
Last Modified: 2011-09-20
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.
0
Comment
Question by:Molando
  • 3
  • 2
5 Comments
 
LVL 4

Accepted Solution

by:
ceoworks earned 600 total points
ID: 12564066
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);
begin
  AThread.Connection.ReadTimeOut := 10;
end;
0
 
LVL 2

Author Comment

by:Molando
ID: 12582381
As nobody can answer my question about connection counting, assigning all points to answer about timeouts.
0
 
LVL 4

Expert Comment

by:ceoworks
ID: 12584083
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
0
 
LVL 2

Author Comment

by:Molando
ID: 12592234
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.

0
 
LVL 4

Expert Comment

by:ceoworks
ID: 12595267
I'm happy to hear that your problem solved :)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

809 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