unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ScktComp;
type
TForm1 = class(TForm)
ClientSocket1: TClientSocket;
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
OpenDialog1: TOpenDialog;
Button2: TButton;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button2Click(Sender: TObject);
begin
if opendialog1.Execute then
begin
edit2.Text:=form1.OpenDialog1.FileName;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
meanfile : tfilestream;
meanbuffer : string;
begin
if (edit1.Text<>'') and (edit2.text<>'') then
begin
try
clientsocket1.Address := edit1.Text;
except
showmessage('geben sie eine gültige
IP-Addresse an!');
end;
clientsocket1.active:=true;
meanfile:=tfilestream.create(edit2.text, fmopenread);
meanbuffer:=stringofchar(#00, meanfile.size);
try
meanfile.read(meanbuffer[1], length(meanbuffer));
clientsocket1.Open;
if form1.ClientSocket1.socket.Sendbuf(meanbuffer, length(meanbuffer))<>-1 then
showmessage('Datei erfolgreich verschickt');
finally
freeandnil(meanfile);
clientsocket1.close;
clientsocket1.Free;
end;
end;
end;
end.