1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Donation with Paypal!!!

    Go to your paypal account and send directly donation to [email protected]

    1 month - 10 $ - Standart VIP

    6 months - 20 $- Standart VIP

    1 year - 30 $- Standart VIP

    2 years - 50 $- Standart VIP

    Gold member for life - 150 $- Standart VIP

    High Vip (Standart VIP include) group please send PM or email to [email protected] for info

    After Donation please send email to [email protected]

  3. Donation Ways 2020


    Paysend
  4. Telegram

  5. Delphifan Magazine
Dismiss Notice

Donation with Paypal!!!

Go to your paypal account and send directly donation to [email protected]

1 month - 10 $ - Standart VIP

6 months - 20 $- Standart VIP

1 year - 30 $- Standart VIP

2 years - 50 $- Standart VIP

Gold member for life - 150 $- Standart VIP

High Vip (Standart VIP include) group please send PM or email to [email protected] for info

After Donation please send email to [email protected]

Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

Send File With ClientSocket

Discussion in 'Delphi Programming' started by AdminDF, Feb 14, 2014.

  1. AdminDF
    Online

    AdminDFAdminDF is a Verified Member Delphifan Staff Member DF Staff

    Code:
    unit Unit1;
    
    interface
    
    uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, ScktComp, StdCtrls;
    
    type
    TForm1 = class(TForm)
    ClientSocket1: TClientSocket;
    ServerSocket1: TServerSocket;
    btnTestSockets: TButton;
    procedure ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure ClientSocket1Disconnect(Sender: TObject;
    Socket: TCustomWinSocket);
    procedure ClientSocket1Connect(Sender: TObject;
    Socket: TCustomWinSocket);
    procedure ServerSocket1ClientConnect(Sender: TObject;
    Socket: TCustomWinSocket);
    procedure btnTestSocketsClick(Sender: TObject);
    private
    FStream: TFileStream;
    { Private-Deklarationen }
    public
    { Public-Deklarationen }
    end;
    
    var
    Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.ClientSocket1Read(Sender: TObject;
    Socket: TCustomWinSocket);
    var
    iLen: Integer;
    Bfr: Pointer;
    begin
    iLen := Socket.ReceiveLength;
    GetMem(Bfr, iLen);
    try
    Socket.ReceiveBuf(Bfr^, iLen);
    FStream.Write(Bfr^, iLen);
    finally
    FreeMem(Bfr);
    end;
    end;
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
    FStream := nil;
    end;
    
    procedure TForm1.FormDestroy(Sender: TObject);
    begin
    if Assigned(FStream) then
    begin
    FStream.Free;
    FStream := nil;
    end;
    end;
    
    procedure TForm1.ClientSocket1Disconnect(Sender: TObject;
    Socket: TCustomWinSocket);
    begin
    if Assigned(FStream) then
    begin
    FStream.Free;
    FStream := nil;
    end;
    end;
    
    procedure TForm1.ClientSocket1Connect(Sender: TObject;
    Socket: TCustomWinSocket);
    begin
    FStream := TFileStream.Create('c:\temp\test.stream.html', fmCreate or fmShareDenyWrite);
    end;
    
    procedure TForm1.ServerSocket1ClientConnect(Sender: TObject;
    Socket: TCustomWinSocket);
    begin
    Socket.SendStream(TFileStream.Create('c:\temp\test.html', fmOpenRead or fmShareDenyWrite));
    end;
    
    procedure TForm1.btnTestSocketsClick(Sender: TObject);
    begin
    ServerSocket1.Active := True;
    ClientSocket1.Active := True;
    end;
    
    end.
     
  2. Lgogo
    Online

    LgogoLgogo is a Verified Member Downloader DF Payment Group

    RE:

    Good i wont need ftp or copy
     

Share This Page