主题:关于TCP/IP文件传输的问题。。。请高手指点。
服务器代码:
procedure TfrmMain.IdTCPServer1Execute(AThread: TIdPeerThread);
begin
with AThread.Connection do
begin
ASize := Min(iFileSize - AFileStream.Size,4);
ReadStream(AFileStream,ASize);
Application.ProcessMessages;
end;
end
客户端代码:
procedure TForm1.TCPSendFile;
begin
//*******
连接代码
//*******
AFileStream := TFileStream.Create(sPath+'\Send\'+zipFileName+'.zip', fmOpenRead);
while AFileStream.Size > AFileStream.Position do
begin
AFileStream.Seek(AFileStream.Position, soFromBeginning);
ASize := Min(AFileStream.Size - AFileStream.Position,4);
IdTCPClient1.OpenWriteBuffer;
IdTCPClient1.WriteStream(AFileStream,False,False,Asize);
IdTCPClient1.CloseWriteBuffer;
Application.ProcessMessages;
end;
end;
程序运行后文件传输不完整。。。。
-----------------------------------
procedure TfrmMain.IdTCPServer1Execute(AThread: TIdPeerThread);
begin
with AThread.Connection do
begin
ASize := Min(iFileSize - AFileStream.Size,4);
ReadStream(AFileStream,ASize);
Application.ProcessMessages;
end;
end
客户端代码:
procedure TForm1.TCPSendFile;
begin
//*******
连接代码
//*******
AFileStream := TFileStream.Create(sPath+'\Send\'+zipFileName+'.zip', fmOpenRead);
while AFileStream.Size > AFileStream.Position do
begin
AFileStream.Seek(AFileStream.Position, soFromBeginning);
ASize := Min(AFileStream.Size - AFileStream.Position,4);
IdTCPClient1.OpenWriteBuffer;
IdTCPClient1.WriteStream(AFileStream,False,False,Asize);
IdTCPClient1.CloseWriteBuffer;
Application.ProcessMessages;
end;
end;
程序运行后文件传输不完整。。。。
-----------------------------------