远程文件传输问题(100分)

  • 主题发起人 主题发起人 sfwany
  • 开始时间 开始时间
S

sfwany

Unregistered / Unconfirmed
GUEST, unregistred user!
我想用INDY 中TIDTCPCLIENT和TIDTCPSERVER两个控件编写一个远程文件传达程序,哪位可提供源程序!如果觉得分不够的话,还可再加!谢了!
 
怎么没人帮忙呀?!!!!!!!![:(][:(][:(]
 
我找到一个例子,告诉我你的email,我发给你。
 
用winsock怎么实现?
SOCKET每次能传多大的数据?
 
sfwany@163.com谢谢lt66了
 
http://wisdomcube.com/stuff/Socket2.rar
用TIdTcpServer和TIdTcpClient做的文件传输的例子
 
app2001
的不错
 
ap2001是可以,但在服务器那端要人工保存,有没有自动保存的呀!
 
//我自己写了一个,在本机进行测试,传输35M的文件没有问题。

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdUDPBase, IdUDPServer, StdCtrls,
IdUDPClient,IdSocketHandle, ComCtrls;

type
TForm1 = class(TForm)
UDPServer: TIdUDPServer;
UDPClient: TIdUDPClient;
LBHotname: TLabel;
LBhostAdress: TLabel;
Label3: TLabel;
Label4: TLabel;
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
ProgressBar1: TProgressBar;
procedure Button1Click(Sender: TObject);
procedure UDPServerUDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
FS: TFileStream;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
LBHotname.Caption := UDPServer.LocalName;
LBhostAdress.Caption :=IntToStr(UDPServer.DefaultPort);
end;

procedure TForm1.UDPServerUDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
var
S :String;
begin
if AData.Size > 0 then
begin
FS.CopyFrom(AData,AData.Size);
S := IntToStr(AData.Size);
ABinding.SendTo(ABinding.PeerIP,ABinding.PeerPort,S[1],length(S));
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
F: TFileStream;
Fbuffer :array[0..1023] of Byte;
ct,recv:integer;
begin
F := TFileStream.Create('F:/QQ/Wrox - Professional C# (C#高级编程).pdf',fmOpenRead);
F.Seek(0,soBeginning);
ProgressBar1.Max := F.Size;
ProgressBar1.Min := 0;
ct := 0;
repeat
ct := F.Read(Fbuffer,1024);
if ct > 0 then
begin
recv := 0;
UDPClient.SendBuffer(Fbuffer,1024);
while recv < ct do
begin
Application.ProcessMessages;
try
recv := recv + StrToInt(UDPClient.ReceiveString());
except
end;
end;
end;
ProgressBar1.Position := ProgressBar1.Position + ct;
until ct = 0;
F.Free;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
FS := TFileStream.Create(Edit1.Text,fmCreate or fmOpenReadWrite);
UDPServer.Active := True;
UDPClient.Active := True;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
FS.Free;
end;
我不知道用远程行不行!你自己试一试了!
 
程序已经发出。
 
有答案給我一分,zwp919@avl.com.cn 感激不盡
 
我想用INDY 中TIDTCPCLIENT和TIDTCPSERVER两个控件编写一个远程文件传达程序,哪位可提供源程序!
 
多人接受答案了。
 
后退
顶部