자료실에 어떤 예제를 보고 따라해본것인데..
예제가 파일하나만 송신하는것을 2개이상 송신하게끔 바꿔보았는데...
쓰레드에 대한 지식이 미흡해 진전을 보지 못하고 있습니다...
바쁘시더라도 한번 검토 해 봐 주세요...
다음은 클라이언트 쪽의 소스 입니다...서버쪽은 바꾸지 않아도 될것같아 그대로 사용 했구요...
unit Client;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient, IniFiles, Gauges, XSocket;
type
TMyThread = class(TThread)
private
Msg: Pekit;
FinishChk : Boolean;
procedure View;
public
procedure Execute; override;
end;
TForm1 = class(TForm)
IdTCPClient1: TIdTCPClient;
ClientGauge: TGauge;
Button2: TButton;
ListBox1: TListBox;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
MyThread: TMyThread;
public
{ Public declarations }
gHost, gPort, gUserID, gPassword : string;
gExeFile, gPath : string;
gFile : String; //압축파일이름
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TMyThread.View;
begin
if Msg.msg = mtText Then
Form1.Memo1.Lines.Add(strpas(Msg.Data))
else if (Msg.msg - mtSSFileNM) in [0..2] Then
begin
Send2UFile(Form1.IdTCPClient1, Msg);
Form1.ClientGauge.MaxValue := Msg.f_1;
Form1.ClientGauge.Progress := Msg.f_2;
end
else if (Msg.msg - mtSSFileST) in [0..3] Then
Recv2UFile(Form1.IdTCPClient1, Msg, FinishChk);
end;
procedure TMyThread.Execute;
begin
while (not Terminated) And (not FinishChk) do
begin
try
FillChar(Msg, mtLens, 0);
Form1.IdTCPClient1.ReadBuffer(Msg, mtLens);
Synchronize(View);
except
Terminate;
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
const
IniName = 'Downcfg.ini';
var
DBCFG: TIniFile;
ExePath : String;
i : integer;
begin
DBCFG := TIniFile.Create(GetCurrentDir+'Downcfg.ini');
gHost := DBCFG.ReadString('DownLoad','FTPHOST','');
gPort := DBCFG.ReadString('DownLoad','PORT','');
//gUserID := DBCFG.ReadString('DownLoad','USERID','');
//gPassword := DBCFG.ReadString('DownLoad','PASSWORD','');
i := 1;
while True do
begin
gExeFile := DBCFG.ReadString('DownLoad','ExeFile'+IntToStr(i),'');
if Trim(gExeFile) <> '' then
begin
ListBox1.Items.Add(gExeFile);
inc(i);
end
else break;
end;
if IdTCPClient1.Connected = False then
begin
IdTCPClient1.Host := gHost;
IdTCPClient1.Port := StrToInt(gPort);
//IdTCPClient1.UserID := gUserID;
//IdTCPClient1.Password := gPassword;
{ try
IdTCPClient1.Connect;
MyThread := TMyThread.Create(true);
MyThread.FreeOnTerminate := true;
MyThread.Resume;
//IdTCPClient1.WriteLn('SEND');
except On E:Exception do
begin
ShowMessage('FTP 서버 ' + gHost + ' 에 연결할 수 없습니다...' + #13#10 + E.Message);
Exit;
end;
end; }
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
const
BuffSize = 4062;
var
Cmd : String;
Buff : Array [0..BuffSize-1] of Char;
CopySize : Integer;
FStream : TFileStream;
i : integer;
begin
{ Cmd := IdTCPClient1.ReadLn('',100);
if Trim(Cmd) = 'PER' then
begin
for i := ListBox1.Items.Count - 1 downTo 0 do
begin
Send2U(IdTCPClient1, ListBox1.Items[i], mtSSFileST);
try
// IdTCPClient1.WriteLn(ListBox1.Items[i]);
FStream := TFileStream.Create(ListBox1.Items[i],fmOpenRead);
ClientGauge.MaxValue := FStream.Size;
while True do
begin
CopySize := FStream.Read(Buff,BuffSize);
if CopySize <> 0 then
begin
IdTCPClient1.WriteBuffer(Buff,CopySize,True);
ClientGauge.Progress := ClientGauge.Progress + CopySize;
end
else Break;
end;
finally
FStream.Free;
end;
end;
end
else if Trim(Cmd) = 'DEN' then
begin
Showmessage('파일 전송 거절');
IdTCPClient1.Disconnect;
end;
}
for i := ListBox1.Items.Count - 1 downTo 0 do
begin
try
IdTCPClient1.Connect;
MyThread := TMyThread.Create(true);
MyThread.FreeOnTerminate := true; //Determines whether the thread object is
//automatically destroyed when the thread terminates.
MyThread.Resume;
except On E:Exception do
begin
ShowMessage('FTP 서버 ' + gHost + ' 에 연결할 수 없습니다...' + #13#10 + E.Message);
Exit;
end;
end;
Send2U(IdTCPClient1, ListBox1.Items[i], mtSSFileST);
MyThread.WaitFor;
if MyThread.FinishChk then
IdTCPClient1.Disconnect;
end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
// MyThread.Free;
// IdTCPClient1.Disconnect;
end;