Recently i got a project that from my perspective is very challenging, and that is create an application that consist of two app, server and client.The client should receive a list of directory from the server app that is in the remote computer, so that computer where the client app resides could select the file or directory for download (much like RAdmin,team viewer, etc). The challenging part is that the project must not use a Delphi component that based on FTP and HTTP model, and because of that the option left is using TSocket.

after all day researching, and trying to compile the app. I found out, that for the first step i have to create a protocol for communication between server and client app. part of script for server app:

if Pos('LIST!',strCommand) = 1 then
begin
 if DirectoryExists(strFile) then
  begin
    strFeedback := 'LIST!';
   Socket.SendText(strFeedBack);
   AllDir; //Create directory List
  end
 else
  begin
   strFeedBack := 'ERROR' + strFile + ' Directory is not Found or a File';
  socket.SendText(strFeedback);
  end;
end;

part of script for client app :

csList :
 begin
   listFiles.Items.Text := Socket.ReceiveText;
  cliStatus := csIdle;
 end;

above script are modified from Mastering Delphi 4 by Marco Cantu.

i find some funny thing in the client app when it’s receiving data transfer
when i put this code

begin
  Stream2 := TFileStream.Create(SaveFileName,fmOpenWrite or fmCreate );
  Screen.Cursor:=crHourGlass;
try
 while true do
  begin
   nReceived := Socket.ReceiveBuf(Buffer,sizeof(Buffer));
   if nReceived <= 0 then Break 
   else Stream2.Write(Buffer,nReceived);
    
   time1 := GetTickCount;
   while GetTickCount - time1 <> 0 do stream.Position := 0;
end; 

data transfer process on client app only receiving 16 Kb data. Since it wasn’t completed data, these data can’t be read. But if script add with some extra variable that using TMemorystream, then data transfer process is success. I’ve tried to send from server to client app with data size 200 Mb it can transmit data and receive successfully.

code script that is being modified would be like following:

begin
  Stream  := TMemoryStream.Create;
  Stream2 := TFileStream.Create(SaveFileName,fmOpenWrite or fmCreate );
  Screen.Cursor:=crHourGlass;
  try
   while true do
     begin
      nReceived := Socket.ReceiveBuf(Buffer,sizeof(Buffer));
      if nReceived <= 0 then Break
     else
      begin
       Stream.Write(Buffer,nReceived);
       Stream2.Write(Buffer,nReceived);
      end;
     time1 := GetTickCount;
     while GetTickCount - time1 <> 0 do stream.Position := 0;
end;