发送端:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ExtDlgs, NMSTRM, Psock,jpeg, ComCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
Edit1: TEdit;
Label1: TLabel;
Button1: TButton;
NMStrm1: TNMStrm;
StatusBar1: TStatusBar;
OpenPictureDialog1: TOpenPictureDialog;
Edit2: TEdit;
Edit3: TEdit;
NMStrm2: TNMStrm;
NMStrm3: TNMStrm;
Label2: TLabel;
Label3: TLabel;
procedure Button1Click(Sender: TObject);
procedure NMStrm1MessageSent(Sender: TObject);
procedure NMStrm1Connect(Sender: TObject);
procedure NMStrm1Disconnect(Sender: TObject);
procedure NMStrm1HostResolved(Sender: TComponent);
procedure NMStrm1Status(Sender: TComponent; Status: String);
procedure NMStrm1PacketSent(Sender: TObject);
procedure NMStrm1InvalidHost(var Handled: Boolean);
procedure NMStrm1ConnectionFailed(Sender: TObject);
procedure NMStrmServ1Status(Sender: TComponent; Status: String);
procedure NMStrm2MessageSent(Sender: TObject);
procedure NMStrm3MessageSent(Sender: TObject);
procedure NMStrm2InvalidHost(var Handled: Boolean);
procedure NMStrm3InvalidHost(var Handled: Boolean);
procedure NMStrm2ConnectionFailed(Sender: TObject);
procedure NMStrm3ConnectionFailed(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 form1.OpenpictureDialog1.Execute then
begin
form1.NMStrm1.Host:=edit1.Text;
form1.NMStrm2.Host:=edit2.Text;
form1.NMStrm3.Host:=edit3.Text;
myfstream:=tFilestream.Create(form1.OpenpictureDialog1.FileName,fmopenread);
try
form1.NMStrm1.PostIt(myfstream);
form1.NMStrm2.PostIt(myfstream);
form1.NMStrm3.PostIt(myfstream);
finally
myfstream.Free;
end;
end;
end;
procedure TForm1.NMStrm1MessageSent(Sender: TObject);
begin
showmessage(' IP地址1发送成功');
end;
procedure TForm1.NMStrm1Connect(Sender: TObject);
begin
statusbar1.SimpleText:='已连接';
end;
procedure TForm1.NMStrm1Disconnect(Sender: TObject);
begin
if statusbar1<>nil then
statusbar1.SimpleText:='已断开';
end;
procedure TForm1.NMStrm1HostResolved(Sender: TComponent);
begin
statusbar1.SimpleText:='host resolved';
end;
procedure TForm1.NMStrm1Status(Sender: TComponent; Status: String);
begin
if statusbar1<>nil then
statusbar1.SimpleText:=status;
end;
procedure TForm1.NMStrm1PacketSent(Sender: TObject);
begin
statusbar1.SimpleText:=inttostr(nmstrm1.BytesSent)+'of'+inttostr(nmstrm1.BytesTotal)+'sent';
end;
procedure TForm1.NMStrm1InvalidHost(var Handled: Boolean);
var
tmpstr:string;
begin
if inputquery('invalid host!','请在对话框1中输入接受方IP地址:',tmpstr) then
begin
nmstrm1.Host:=tmpstr;
handled:=true;
end;
end;
procedure TForm1.NMStrm1ConnectionFailed(Sender: TObject);
begin
showmessage('IP地址1连接失败');
end;
procedure TForm1.NMStrmServ1Status(Sender: TComponent; Status: String);
begin
if statusbar1<>nil then
statusbar1.SimpleText:=status;
end;
procedure TForm1.NMStrm2MessageSent(Sender: TObject);
begin
showmessage(' IP地址2发送成功');
end;
procedure TForm1.NMStrm3MessageSent(Sender: TObject);
begin
showmessage(' IP地址3发送成功');
end;
procedure TForm1.NMStrm2InvalidHost(var Handled: Boolean);
var
tmpstr:string;
begin
if inputquery('invalid host!','请在对话框2中输入接受方IP地址:',tmpstr) then
begin
nmstrm2.Host:=tmpstr;
handled:=true;
end;
end;
procedure TForm1.NMStrm3InvalidHost(var Handled: Boolean);
var
tmpstr:string;
begin
if inputquery('invalid host!','请在对话框3中输入接受方IP地址:',tmpstr) then
begin
nmstrm3.Host:=tmpstr;
handled:=true;
end;
end;
procedure TForm1.NMStrm2ConnectionFailed(Sender: TObject);
begin
showmessage('IP地址2连接失败');
end;
procedure TForm1.NMStrm3ConnectionFailed(Sender: TObject);
begin
showmessage('IP地址3连接失败');
end;
end.