我的远程传送文件的代码到底错在什么地方??(100分)

  • 主题发起人 主题发起人 dgidqs
  • 开始时间 开始时间
D

dgidqs

Unregistered / Unconfirmed
GUEST, unregistred user!
用这些代码在自己电脑上测试一点问题都没有

可以如果在网上测试的话,如果传送的文件稍微大一点

就不行了??

这到底是为什么


==================server=====================================================
procedure TfileForm.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
mystr:string;
FL:File;
up_buf : array [0..1023] of byte;
Bsent:integer;
filesize:integer;
filehand:integer;
begin
mystr:=Socket.ReceiveText;
if mystr[1]+mystr[2]+mystr[3]+mystr[4]+mystr[5]+mystr[6]='~getin' then
begin
delete(mystr,1,6);
try
tempfilename:=mystr;
filehand:=_lopen(pchar(mystr),OF_READ);
filesize:=getfilesize(filehand,nil);
serversocket1.Socket.Connections[0].SendText('_fsize'+inttostr(filesize));
finally
_lclose(filehand);
end;
end
else if mystr[1]+mystr[2]+mystr[3]+mystr[4]+mystr[5]+mystr[6]='~downl' then
begin
//------------------------传送
if tempfilename<>'' then
begin
try
AssignFile(FL,tempfilename);
{$I-}
FileMode :=0;
ReSet (FL, 1);
repeat
BlockRead (FL, UP_BUF, 1024, BSent);
Application.ProcessMessages;
sleep(1);
if BSent>0 then
Socket.SendBuf (UP_BUF, BSent);
until (Bsent=0);///EOF (Fl);
{$I+}
Closefile(FL);
except
end;
end;
//-----------------------
end;

end;
=======================================================================

===========================client==========================================
procedure TFileForm.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
var
mystr:string;
AC:integer;
buffer:array [0..10000] of byte; //设置接收缓冲区
begin
if downtag=true then
begin
//----------------------------
Application.ProcessMessages;
AC:=Socket.ReceiveBuf (buffer, 1024);
if AC>0 then
begin
RLen:=RLen+AC;
BlockWrite (F_down,buffer, AC);
ProgressBar1.Position:=RLen;
end;
if Rlen>=filesize then
begin
downtag:=false;
fileSize:=0;
RLen:=0;
Closefile(F_down);
showmessage('下载完毕');
ProgressBar1.Position:=0;
FileForm.Hide;
exit;
end;
//------------------------------
end
else
begin
mystr:=Socket.ReceiveText;
if mystr[1]+mystr[2]+mystr[3]+mystr[4]+mystr[5]+mystr[6]='_fsize' then
begin
delete(mystr,1,6);
filesize:=strtoint(mystr);
downtag:=true;
ProgressBar1.Max:=filesize;
ProgressBar1.Position:=0;
ClientSocket1.Socket.SendText('~downl');
end;

end;


end;
=================================================================================
 
好像在帮助上看到传输大文件要通过TWinSocketStream来实现。不然会有问题。
 
问题解决

 
后退
顶部