BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to correctly disconnect TCPClients

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Internet Winsock
View previous topic :: View next topic  
Author Message
Marcelo Rodrigues
Guest





PostPosted: Fri Apr 23, 2004 4:56 pm    Post subject: How to correctly disconnect TCPClients Reply with quote



Hi,

I'm using Indy TCPServer on a project. This server accepts remote client
connections and keep this connections opened.

When I try to close the server application I get the 'Thread Timeout'
Excption. Following my close procedure:

procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
var
List: TList;
I: Integer;
begin
List := Server.Threads.LockList;
try
for I := 0 to List.Count - 1 do
begin
try
TIdPeerThread(List.Items[I]).Connection.DisconnectSocket;
while not TIdPeerThread(List.Items[I]).Terminated do
TIdPeerThread(List.Items[I]).Terminate;
except
on E: Exception do
begin
AddToLogView('ERRO','Thread paralizado',now,3);
AddToLogView('ERRO','Erro (' + FormatDateTime('dd/mm/yyyy', Now) +
') [' + E.ClassName + ']: ' + E.Message,now,3);
TIdPeerThread(List.Items[I]).Stop;
end; //on
end; //try
end; //for
finally
Server.Threads.UnlockList;
end;

IncomingList.Free;
OutGoingList.Free;
ClientList.Free;
Server.Active := false;
end;


Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Fri Apr 23, 2004 7:06 pm    Post subject: Re: How to correctly disconnect TCPClients Reply with quote




"Marcelo Rodrigues" <marcelo (AT) pathcompany (DOT) com.br> wrote


Quote:
When I try to close the server application I get the 'Thread Timeout'
Excption. Following my close procedure:

What does your actal thread code look like, and what it the
TerminateWaitTime property set to? Such an error will occur if your own
code is not allowing the threads to terminate in a timely fashion.

Quote:
while not TIdPeerThread(List.Items[I]).Terminated do
TIdPeerThread(List.Items[I]).Terminate;

You should not be doing that. The Terminated property does not get set to
true when the thread is finished. It is only set to true when you call
Terminate(). If anything, you should be calling Terminate() and then
waiting for the Stopped property instead. Even then, you really shouldn't
be doing any waiting yourself at all in the first place.


Gambit



Back to top
Marcelo Rodrigues
Guest





PostPosted: Fri Apr 23, 2004 7:19 pm    Post subject: Re: How to correctly disconnect TCPClients Reply with quote



Hi,

TerminateWaitTime is set to default value : 5000
This is how may Execute is:

procedure TfrmMainSrv.ServerExecute(AThread: TIdPeerThread);
var
data : string;
begin

try
while AThread.Connection.Connected do
begin
data := AThread.Connection.ReadLn;
if length( data ) > 0 then
ProcessData( Data, AThread );
end;
except
{on E: Exception do
begin
memo1.lines.insert(0,format('Erro lendo TCP: %s',[E.Message]));
AddToLogView('ERRO',format('Erro lendo TCP: %s',[E.Message]),now,3);
end; //on }
end;

end;

Marcelo

"Remy Lebeau (TeamB)" <gambit47.no.spam (AT) no (DOT) spam.yahoo.com> escreveu na
mensagem news:40896a9f$1 (AT) newsgroups (DOT) borland.com...
Quote:

"Marcelo Rodrigues" <marcelo (AT) pathcompany (DOT) com.br> wrote in message
news:40894aa4$1 (AT) newsgroups (DOT) borland.com...

When I try to close the server application I get the 'Thread Timeout'
Excption. Following my close procedure:

What does your actal thread code look like, and what it the
TerminateWaitTime property set to? Such an error will occur if your own
code is not allowing the threads to terminate in a timely fashion.

while not TIdPeerThread(List.Items[I]).Terminated do
TIdPeerThread(List.Items[I]).Terminate;

You should not be doing that. The Terminated property does not get set to
true when the thread is finished. It is only set to true when you call
Terminate(). If anything, you should be calling Terminate() and then
waiting for the Stopped property instead. Even then, you really shouldn't
be doing any waiting yourself at all in the first place.


Gambit





Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Internet Winsock All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.