I have two programs, one for the server and another for the client.
The server sends a file to the client. In the client, I use the TIdTCPClient
, TIdThreadComponent
, and TIdAntiFreeze
components.
The file is well created, but the thread never finishes. When debugging, I never get to Fs.Free
.
This is my client code:
procedure TForm1.IdThreadComponentRun(Sender: TIdThreadComponent);
var
MsgDuServeur: string;
Taille: Integer;
Fs : TFileStream;
begin
MsgDuServeur:= Trim(IdTCPClient.IOHandler.ReadLn(nil));
MemoService.Lines.Add('Serveur : ' + MsgDuServeur);
if (MsgDuServeur = 'RECUP_ENCOURS') then
begin
try
Fs:= TFileStream.Create('C:\temp\client\1test.cds', fmCreate);
try
IdTCPClient.IOHandler.LargeStream:= True;
Taille:= IdTCPClient.IOHandler.ReadInt64();
IdTCPClient.IOHandler.ReadStream(Fs, -1, False);
IdThreadComponent1.Active:= False;
finally
Fs.Free;
end;
except
on E: Exception do
_MessageDlg(E.message, mtWarning, [mbOK], 0);
end;
end;
end;
this is my server code
procedure TServiceServeurTrf.IdTCPServerExecute(AContext: TIdContext);
var
Flux: TMemoryStream;
LStreamSize : int64;
begin
try
// Transfert de fichiers volumineux
Context.Connection.Socket.WriteLn('RECUP_ENCOURS');
AContext.Connection.IOHandler.LargeStream:= True;
Flux:= TMemoryStream.Create;
try
Flux.LoadFromFile(C:\Windows\Temp\Transfert\3000\1test.cds);
Flux.Position:= 0;
AContext.Connection.IOHandler.Write(Flux.Size);
AContext.Connection.IOHandler.Write(Flux, 0, True);
finally
FreeAndNil(Flux);
end;
except
EcrireLog('Erreur');
end;
end;
i deleted the antifreeze and after ReadStream() i use IdThreadComponent1.Active:= False; Now it's ok. How synchronised ? Indeed i want use progressbar with IdTCPClientWork, IdTCPClientWorkBegin, IdTCPClientWorkEnd but i don't see it progress