 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Marcelo Rodrigues Guest
|
Posted: Fri Apr 23, 2004 4:56 pm Post subject: How to correctly disconnect TCPClients |
|
|
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
|
Posted: Fri Apr 23, 2004 7:06 pm Post subject: Re: How to correctly disconnect TCPClients |
|
|
"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
|
Posted: Fri Apr 23, 2004 7:19 pm Post subject: Re: How to correctly disconnect TCPClients |
|
|
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 |
|
 |
|
|
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
|
|