Indy의 "IdTCPClient"와 "IdTCPServer"로 소용량 파일전송을 만들려고 합니다.
아래 소스는 "IdTCPClient"에서 파일을 전송하고자 하는데 자꾸 죽네요...
고수님들의 조언을 부탁드립니다.
// IdTCPServer
procedure TForm1.IdTCPServerExecute(AThread: TIdPeerThread);
var
 S : String;
 Stream : TFileStream;
begin
 Memo1.Lines.Add('IdTCPServerExecute : ' + AThread.Connection.Binding.PeerIP);
 S := AThread.Connection.ReadLn;
 if S = 'Ready' then
 begin
   Stream := TFileStream.Create(ExtractFilePath(Application.ExeName) + AThread.Connection.Binding.PeerIP + '.bmp',fmCreate);
   try
     While AThread.Connection.Connected do
     begin
       AThread.Connection.ReadStream(Stream, -1, True);
       FreeAndNil(Stream);
       AThread.Connection.Disconnect;
     end;
   finally
     Stream.Free;
   end;
 end;
end;
// IdTCPClient
procedure TForm1.Button2Click(Sender: TObject);
begin
 if Not IdTCPClient.Connected then
 begin
   if FileExists(ExtractFilePath(Application.ExeName) + '1.bmp') then
   begin
     IdTCPClient.Connect;
     if IdTCPClient.Connected then
     begin
       IdTCPClient.WriteLn('Ready');
       SendStream := TFileStream.Create(ExtractFilePath(Application.ExeName) + '1.bmp',fmOpenRead);
       try
         IdTCPClient.OpenWriteBuffer;
         IdTCPClient.WriteStream(SendStream);
         
         // 여기에서 ShowMessage(''); 로 잠시 멈추고 하면 전송되는데 sleep 등으로 임의로 멈춘 후에 하면 안되네요...  
         
         IdTCPClient.CloseWriteBuffer;
       finally
         SendStream.Free;
       end;
       IdTCPClient.Disconnect;
     end;
   end;
 end;
end; 
			 
	
	
    
    
	
	
    
    
    
일단 WriteStream에서 한꺼번에 다 보내지 말고
while문을 이용하여 조금씩(2048바이트정도) 나누어서 WriteBuffer로 보내 보시기 바랍니다.
임준 wrote:
> Indy의 "IdTCPClient"와 "IdTCPServer"로 소용량 파일전송을 만들려고 합니다.
> 아래 소스는 "IdTCPClient"에서 파일을 전송하고자 하는데 자꾸 죽네요...
>
> 고수님들의 조언을 부탁드립니다.
>
> // IdTCPServer
> procedure TForm1.IdTCPServerExecute(AThread: TIdPeerThread);
> var
> S : String;
> Stream : TFileStream;
> begin
> Memo1.Lines.Add('IdTCPServerExecute : ' + AThread.Connection.Binding.PeerIP);
>
> S := AThread.Connection.ReadLn;
> if S = 'Ready' then
> begin
> Stream := TFileStream.Create(ExtractFilePath(Application.ExeName) + AThread.Connection.Binding.PeerIP + '.bmp',fmCreate);
> try
> While AThread.Connection.Connected do
> begin
> AThread.Connection.ReadStream(Stream, -1, True);
> FreeAndNil(Stream);
> AThread.Connection.Disconnect;
> end;
> finally
> Stream.Free;
> end;
> end;
> end;
>
> // IdTCPClient
>
> procedure TForm1.Button2Click(Sender: TObject);
> begin
> if Not IdTCPClient.Connected then
> begin
> if FileExists(ExtractFilePath(Application.ExeName) + '1.bmp') then
> begin
> IdTCPClient.Connect;
>
> if IdTCPClient.Connected then
> begin
> IdTCPClient.WriteLn('Ready');
>
> SendStream := TFileStream.Create(ExtractFilePath(Application.ExeName) + '1.bmp',fmOpenRead);
> try
> IdTCPClient.OpenWriteBuffer;
> IdTCPClient.WriteStream(SendStream);
>
> // 여기에서 ShowMessage(''); 로 잠시 멈추고 하면 전송되는데 sleep 등으로 임의로 멈춘 후에 하면 안되네요...
>
> IdTCPClient.CloseWriteBuffer;
> finally
> SendStream.Free;
> end;
> IdTCPClient.Disconnect;
> end;
> end;
> end;
> end;