发送与接收文件的问题,急急急(附源码)(30分)

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

samen

Unregistered / Unconfirmed
GUEST, unregistred user!
IDTCPSERVER IDTCPCLIENT如何发送和接收???
执行下面代码,提示SOCKET 10054错误。
procedure TForm1.SpeedButton1Click(Sender: TObject);
const blocklen=4096;
var
flen:integer;
blocknum:integer;
remainlen:integer;
i:integer;
begin
idtcpclient1.Connect;
assignfile(Ftrans,'c:/a.txt');
reset(ftrans);
flen:=filesize(ftrans);
blocknum:=flen div blocklen;
remainlen:=flen mod blocklen;

for i:=0 to blocknum-1 do //文件分块的字节块发送
begin
blockread(ftrans,blockbuf[0],blocklen);
idtcpclient1.WriteBuffer(blockbuf,blocklen,false);
end;
if (remainlen>0) then //文件剩余的字节数发送
begin
blockread(ftrans,blockbuf[0],remainlen);
idtcpclient1.WriteBuffer(blockbuf,remainlen,false);
end;
closefile(ftrans);
end;

procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
var
Ftrans:file of byte;
blockbuf:ARRAY[0..4096-1] of byte;
recelen:integer;
begin
assignfile(Ftrans,'c:/b.txt');
recelen:=AThread.Connection.RecvBufferSize;
AThread.Connection.ReadBuffer(blockbuf,recelen);
rewrite(ftrans);
while (recelen>0) do
begin
blockwrite(ftrans,blockbuf[0],recelen);
recelen:=AThread.Connection.RecvBufferSize;
AThread.Connection.ReadBuffer(blockbuf,recelen);
end;
closefile(ftrans);
end;
 
请修改一下上面的源代码。
 
没人能回答这个问题吗?
 
INDY控件使用的人那么少吗?
 
后退
顶部