200分求一个多个客户用用idtcpserver端通过有固定IP服务器 聊天,发送文件的例子。 分不够可以另开贴子。 ( 积分: 200 )

  • 主题发起人 主题发起人 tl_lyq
  • 开始时间 开始时间
T

tl_lyq

Unregistered / Unconfirmed
GUEST, unregistred user!
邮箱:tl_liuyq@sina.com


另用idtcp...与idudp...实现上述功能有什么区别呢。 idtcp方式所有的数据都要通过服务器转发吗。对服务器负担要求如何
如果分少可以另加,请保证能稳定工作。
 
邮箱:tl_liuyq@sina.com


另用idtcp...与idudp...实现上述功能有什么区别呢。 idtcp方式所有的数据都要通过服务器转发吗。对服务器负担要求如何
如果分少可以另加,请保证能稳定工作。
 
这么惨吗,没一个肯帮忙的,给点思路也可以啊
 
为什么不用,Socket,INDY呢?
帮你顶...
 
qq:42872272有
 
我做好一个远程截屏的,修改一下可以改成传送文件,想要 yygymjgw32167@163.com

我那也有一个文件传输的教程
 
好象楼主已经看不到了...
 
多谢大家,问题已经解决
 
用idUDPserver和idUDPClient传文件的例子



在网上找了一个例子 但是只能一对一的传



如果 两个Client同时往Server传收到的文件会有问题

那个代码如下

---------------------

Client:

Var ReceivedString:String;

Mem:TFileStream;

p:Array[0..1023] of byte;

Posi,Len:Integer;

begin

if OpenDialog1.Execute then

begin

IdUDPClient1.Host:=Edit1.Text;

IdUDPClient1.Active:=True;

IdUDPClient1.Send('Send file:File Name:'+OpenDialog1.FileName);

ReceivedString := IdUDPClient1.ReceiveString();

if UpperCase(ReceivedString)='RECIVED FILE NAME OK!' then

begin

Mem:=TFileStream.Create(OpenDialog1.FileName,fmOpenRead);

try

Posi:=0;

IdUDPClient1.Send('Send File:File Length:'+IntToStr(Mem.Size));

ReceivedString := IdUDPClient1.ReceiveString();

if UpperCase(ReceivedString)='RECIVED FILE LENGTH OK!' then

begin

While Posi<Mem.Size do//一次只发1024个字节,字节数不能太多,不过应该还可以增加一些.

begin

Len:=1024;

if Mem.Size-Posi<1024 then

Len:=Mem.Size-Posi;

Mem.Read(p,Len);

IdUDPClient1.SendBuffer(P,Len);

Inc(Posi,Len);

Gauge1.Progress:=Round(Posi/Mem.Size*100);

ReceivedString := IdUDPClient1.ReceiveString();

if UpperCase(ReceivedString)<>'RECIVED FILE PACKAGE OK!' then

Break;

Application.ProcessMessages;

end;

IdUDPClient1.Send('Send File:File End!');

end else

ShowMessage('Send file cancel!');

finally

Mem.Free;

end;

end;

end;

end;



Server:

var FileName:string;

FileSize:integer;

Mem:TFileStream;

//这3个是单元变量 偶觉得问题就在这





Var Str:String;

begin

AData.Seek(0,0);

SetLength(Str,AData.Size);

AData.Read(Str[1],AData.Size);

if Pos('Send file:File Name:',Str)>0 then

begin

Delete(Str,1,Length('Send file:File Name:'));

FileName:=Str;

Str:='Recived File Name OK!';

ABinding.SendTo(ABinding.PeerIP, ABinding.PeerPort, Str[1], Length(Str));

end else if Pos('Send File:File Length:',Str)>0 then

begin

Delete(Str,1,Length('Send File:File Length:'));

FileSize:=StrToIntDef(Str,0);

SaveDialog1.FileName:=FileName;

if SaveDialog1.Execute then

begin

FileName:=SaveDialog1.FileName;

if FileExists(FileName) then

DeleteFile(FileName);

if Mem<>nil then

begin

Mem.Free;

Mem:=nil;

end;

if not FileExists(FileName) then

Mem:=TFileStream.Create(FileName,fmOpenReadWrite or fmCreate)

else

Mem:=TFileStream.Create(FileName,fmOpenReadWrite);

Str:='Recived File Length OK!';

ABinding.SendTo(ABinding.PeerIP, ABinding.PeerPort, Str[1], Length(Str));

end else

begin

Str:='Recived File Length Cancel!';

ABinding.SendTo(ABinding.PeerIP, ABinding.PeerPort, Str[1], Length(Str));

end;

end else if Pos('Send File:File End!',Str)>0 then

begin

if Mem<>nil then

begin

Mem.Free;

Mem:=nil;

Str:='Recived File OK!';

ABinding.SendTo(ABinding.PeerIP, ABinding.PeerPort, Str[1], Length(Str));

end;

FileName:='';

FileSize:=0;

end

else

begin

if Mem<>nil then

begin

Mem.Seek(0,2);

AData.Seek(0,0);

Mem.CopyFrom(AData,AData.Size);

Gauge1.Progress:=Round(Mem.Size/FileSize*100);

Str:='Recived File Package OK!';

ABinding.SendTo(ABinding.PeerIP, ABinding.PeerPort, Str[1], Length(Str));

Application.ProcessMessages;

end;

end;

end;
 
后退
顶部