如何在internet上进行一点对多点的广播式传输文件(200分)

  • 主题发起人 主题发起人 jzg2002
  • 开始时间 开始时间
J

jzg2002

Unregistered / Unconfirmed
GUEST, unregistred user!
那位朋友有源码,给我一份,我只想传10K左右的文件,而且只要3,5个点接收就行了
我的邮箱;jzg2727@sohu.com
谢谢了
 
3、5个点用不上广播
 
用FTP就可以了,文件在internet传用UDP容易丢包哦
 
其实就相当于组播或多播,说成广播确实不恰当,还请各位多帮忙
 
多播在internet根本无法实现!
 
象你这样,客户端岂不要时时在等待?当服务器端传送完毕,客户端收没收到你如何知道!
我看,你的客户不是很多,不如在服务器端用多线程,每一个客户一个岂不省事
 
我现在对一些基本的问题还没搞清楚,我在作一点对一点传输时,服务端放在接收方,
现在看来一点对多点发送的话,服务端应该放在发送端了,不知道我说的对不对.
 
发送端:
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.
 
接受答案了.
 

Similar threads

D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部