Newsgroups : Borland : borland.public.delphi.internet.winsock : 2005 Feb : Transfer Large File through TCPConnection in 8192 bytes pieces in Indy 10

www.cryer.info
Managed Newsgroup Archive

Transfer Large File through TCPConnection in 8192 bytes pieces in Indy 10

Subject:Transfer Large File through TCPConnection in 8192 bytes pieces in Indy 10
Posted by:"Pascal Batzli Jr" (pascal..@terra.com.br)
Date:Sun, 6 Feb 2005 02:20:04

Hello,
I need to transfer large files using TIdTCPServer and TIdTCPClient 8192
bytes at a time. With Indy 8, everything worked out fine with the code
below:

procedure TCCBServerComm.TransmitirArquivo(fsArquivo: TFileStream;
iCodAplicacaoTransmitida, iCodVersao, iByteInicial: Integer);
var
  dtTempo: TDateTime;
  pBuffer: array [1..8192] of byte;
  iTamBuffer, iTamArquivo, iTamTransmitido: Integer;
  aErros: OleVariant;
begin
  dtTempo := Now;
  iTamTransmitido := 0;
  iTamBuffer := SizeOf(pBuffer);
  iTamArquivo := fsArquivo.Size;
  oThread.Connection.WriteInteger(iTamArquivo);
  while iTamBuffer > 0 do
  begin
    iTamBuffer := fsArquivo.Read(pBuffer, SizeOf(pBuffer));
    oThread.Connection.WriteBuffer(pBuffer, iTamBuffer);
    iTamTransmitido := iTamTransmitido + iTamBuffer;
  end;
end;

However, now with Indy 10, there's no more WriteBuffer, only Write using
TBytes, wich cannot be used with TFileStream. How can I transfer a file
piece by piece and save each piece into a TFileStream?

Thank you in advance.

Replies:

www.cryer.info
Managed Newsgroup Archive