Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Netzwerke (https://www.delphipraxis.net/14-netzwerke/)
-   -   Delphi How to avoid the transfer TCPServer TCPClient (https://www.delphipraxis.net/145975-how-avoid-transfer-tcpserver-tcpclient.html)

haidomingo 11. Jan 2010 18:13


How to avoid the transfer TCPServer TCPClient
 
How to avoid the receive (if not exists) or discard file (if exists)
My code is

Send code:
Delphi-Quellcode:
...
    TCPAggiorna.SendCmd ('aggiorna');
    for i:=0 to ElencoFile.Count - 1 do begin
       FStream := TFileStream.Create(ElencoFile[i], fmOpenRead, fmShareDenyWrite);
       TCPAggiorna.IOHandler.WriteLn(ExtractFileName(ElencoFile[i]));
       TCPAggiorna.IOHandler.LargeStream := True;
       TCPAggiorna.IOHandler.Write(FStream, 0, True);
       FreeAndNil(FStream);
    end;
    TCPAggiorna.IOHandler.WriteLn('Finito');
    ....
Receive code

Delphi-Quellcode:
Dir := AppPath;
       FileName:='';
       i:=202;
       repeat
         inc(i);
         FileName:= ASender.Context.Connection.IOHandler.ReadLn;
         if (FileName <> 'Finito') then begin
            if (FileExists(Dir+FileName)) then begin

               // Insert here the code to discard file

               ASender.Context.Connection.IOHandler.WriteLn (IntToStr(i)+' File '+FileName+' received');
            end
            else begin
               FStream := TFileStream.Create(Dir+FileName, fmCreate, fmOpenWrite);
               ASender.Context.Connection.IOHandler.LargeStream := True;
               ASender.Context.Connection.IOHandler.ReadStream(FStream, -1);
               FreeAndNil(FStream);
               ASender.Context.Connection.IOHandler.WriteLn (IntToStr(i)+' File '+FileName+' discarded');
            end;
         end;
        until FileName='Finito';

Klaus01 11. Jan 2010 21:00

Re: How to avoid the transfer TCPServer TCPClient
 
Isn't there a function like Delphi-Referenz durchsuchendeleteFile there?

Regards
Klaus

sx2008 12. Jan 2010 05:41

Re: How to avoid the transfer TCPServer TCPClient
 
The receiver doesn't know where the file's data ends and the filename of the next file starts.
You have to send the length of each file.
Otherwise it's impossible to separate the TCP/IP datastream into different files.
Code:
filename<CR><LF>filelength<CR><LF>file content


Alle Zeitangaben in WEZ +1. Es ist jetzt 00:07 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz