Delphi ActiveX
Delphi ActiveX
Receive a Block of Bytes to a File
See more Socket/SSL/TLS Examples
Demonstrates Socket.ReceiveBytesToFile, which receives one available block of bytes and appends it to a file.
The file path is relative to the application's current working directory. An absolute path may also be used. Supply the path appropriate to your own environment.
Background. Any buffered data is written first; otherwise a single receive operation is performed. The method appends, so repeated calls accumulate received blocks in the file.
Chilkat Delphi ActiveX Downloads
var
success: Integer;
socket: TChilkatSocket;
bTls: Integer;
maxWaitMs: Integer;
begin
success := 0;
socket := TChilkatSocket.Create(Self);
// Connect to the server using TLS.
bTls := 1;
maxWaitMs := 5000;
success := socket.Connect('example.com',5000,bTls,maxWaitMs);
if (success = 0) then
begin
Memo1.Lines.Add(socket.LastErrorText);
Exit;
end;
// The file path is relative to the application's current working directory. An absolute path
// may also be used. Supply the path appropriate to your own environment.
// Receive one available block of bytes and append it to a file. If bytes are already buffered,
// they are used first; otherwise a single receive operation is performed.
success := socket.ReceiveBytesToFile('qa_output/received.dat');
if (success = 0) then
begin
Memo1.Lines.Add(socket.LastErrorText);
Exit;
end;
Memo1.Lines.Add('Received block appended to the file.');