unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, StdCtrls, Psock, NMSTRM, ExtCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
NMStrm1: TNMStrm;
NMStrmServ1: TNMStrmServ;
Button1: TButton;
Label2: TLabel;
Edit2: TEdit;
StatusBar1: TStatusBar;
Bevel1: TBevel;
Panel1: TPanel;
procedure Button1Click(Sender: TObject);
procedure NMStrm1Connect(Sender: TObject);
procedure NMStrm1ConnectionFailed(Sender: TObject);
procedure NMStrm1Disconnect(Sender: TObject);
procedure NMStrm1HostResolved(Sender: TComponent);
procedure NMStrm1InvalidHost(var Handled: Boolean);
procedure NMStrm1MessageSent(Sender: TObject);
procedure NMStrm1PacketSent(Sender: TObject);
procedure NMStrm1Status(Sender: TComponent; Status: String);
procedure NMStrmServ1MSG(Sender: TComponent; const sFrom: String;
strm: TStream);
procedure NMStrmServ1ClientContact(Sender: TObject);
procedure NMStrmServ1Status(Sender: TComponent; Status: String);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
MyFStream:TfileStream;
begin
If opendialog1.Execute then
begin
NMStrm1.Host :=edit2.text;//指定主机
NMStrm1.FromName :=edit1.text;
MyFStream:=TfileStream.Create(opendialog1.filename,fmopenRead);//创建流对象
try
NMStrm1.PostIt (MyFStream);
finally
MyFStream.Free ;
end;
end;
end;
procedure TForm1.NMStrm1Connect(Sender: TObject);
begin
Statusbar1.SimpleText :='Connected';
end;
procedure TForm1.NMStrm1ConnectionFailed(Sender: TObject);
begin
Showmessage('connection Failed');
end;
procedure TForm1.NMStrm1Disconnect(Sender: TObject);
begin
If statusbar1<>nil then
Statusbar1.SimpleText :='disconnected';
end;
procedure TForm1.NMStrm1HostResolved(Sender: TComponent);
begin
Statusbar1.SimpleText :='Host Resolved';
end;
procedure TForm1.NMStrm1InvalidHost(var Handled: Boolean);
var
TmpStr:string;
begin
If inputquery('Invalid Host!','Specify a new host:',TmpStr) then
begin
NMStrm1.Host :=TmpStr;
Handled:=true;
end;
end;
procedure TForm1.NMStrm1MessageSent(Sender: TObject);
begin
showmessage('Stream sent');
end;
procedure TForm1.NMStrm1PacketSent(Sender: TObject);
begin
Statusbar1.SimpleText :=Inttostr(NMStrm1.BytesSent)+'of'+Inttostr(NMStrm1.bytestotal)+'sent';
end;
procedure TForm1.NMStrm1Status(Sender: TComponent; Status: String);
begin
if statusbar1<>nil then
Statusbar1.SimpleText :=status;
end;
procedure TForm1.NMStrmServ1MSG(Sender: TComponent; const sFrom: String;
strm: TStream);
var
MyFstream:TfileStream;
begin
if savedialog1.Execute then
begin
MyFstream:=tfileStream.create(savedialog1.filename,fmcreate);
try
MyFstream.copyfrom(strm,strm.size);
finally
MYFstream.free;
end;
end;
end;
procedure TForm1.NMStrmServ1ClientContact(Sender: TObject);
begin
NMStrmserv1.ReportLevel :=Status_Basic;
NMStrmserv1.TimeOut :=90000;//设置超时
Statusbar1.SimpleText :='Client connected';//显示状态
end;
procedure TForm1.NMStrmServ1Status(Sender: TComponent; Status: String);
begin
if Statusbar1<> nil then
statusbar1.SimpleText :=status;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
edit2.text:='';
edit1.text:='';
end;
end.