S
sunf71
Unregistered / Unconfirmed
GUEST, unregistred user!
目的:客户端告诉服务器用户名和发送的文件名,发送文件给服务器,服务器接收文件进行处理。
代码:
服务器端
user:=Athread.Connection.ReadLn;
if Length(user)<8 then
begin
RecordOperation('用户'+user+'上传数据');
Exit;
end;
AFileStream := TFileStream.Create('temp.xls', fmCreate);
AThread.Connection.ReadStream(AFileStream,-1,true);
count:=AfileStream.Size;
FreeAndNil(AFileStream);
ImportExcel(ExtractFilePath(paramstr(0))+'temp.xls');
客户端
IdTCPClient1.Port := 6000;
//端口
IdTCPClient1.Connect;
//连接
IdTCPClient1.WriteLn(gUserName);
AFileStream := TFileStream.Create(ExtractFilePath(paramstr(0))+'temp.xls', fmOpenRead);
With IdTcpClient1do
OpenWriteBuffer;
WriteStream(AFileStream, true, false);
CloseWriteBuffer;
Disconnect;
end;
AFileStream.Free;
问题:服务器接收到的文件不全,去掉user:=Athread.Connection.ReadLn;和IdTCPClient1.WriteLn(gUserName);则接收正常。请问是什么原因?正确做法是什么?
代码:
服务器端
user:=Athread.Connection.ReadLn;
if Length(user)<8 then
begin
RecordOperation('用户'+user+'上传数据');
Exit;
end;
AFileStream := TFileStream.Create('temp.xls', fmCreate);
AThread.Connection.ReadStream(AFileStream,-1,true);
count:=AfileStream.Size;
FreeAndNil(AFileStream);
ImportExcel(ExtractFilePath(paramstr(0))+'temp.xls');
客户端
IdTCPClient1.Port := 6000;
//端口
IdTCPClient1.Connect;
//连接
IdTCPClient1.WriteLn(gUserName);
AFileStream := TFileStream.Create(ExtractFilePath(paramstr(0))+'temp.xls', fmOpenRead);
With IdTcpClient1do
OpenWriteBuffer;
WriteStream(AFileStream, true, false);
CloseWriteBuffer;
Disconnect;
end;
AFileStream.Free;
问题:服务器接收到的文件不全,去掉user:=Athread.Connection.ReadLn;和IdTCPClient1.WriteLn(gUserName);则接收正常。请问是什么原因?正确做法是什么?