IDtcpconnection组件,writeln()和writebuffer()有什么区别?不是那么简单哦
server端收到传输命令后开始传送文件,客户端用readln()发送命令可以,但用writebuffer()不可以,为什么?
client端程序:
exepath := ExtractFilepath(application.ExeName) + 'maps\';
Commblock.Command := 'shengji';
idtcpclient1.WriteBuffer(commblock, SizeOf (commblock),true); //发送升级请求
UpdateStream:=TMemoryStream.Create;
try
idtcpclient1.ReadStream(UpdateStream,-1,false); //读出内存流到stream,运行到这里出错“stream read error”
UpdateStream.Seek(0, soFromBeginning);
DeCompressFiles(exepath,UpdateStream);
Sleep(200);//等待解压过程结束
Caption:=Caption+'-->升级成功.';
finally
UpdateStream.Free;
end;
server端程序:
AThread.Connection.ReadBuffer (CommBlock, SizeOf(CommBlock));
order := commblock.Command;
UpdateFileStream:=TFileStream.Create(UpdateFileName,fmShareDenyRead);//把文件变成文件流
with AThread.Connection do
begin
try
if order='UPDATE' then //如果客户要求升级
begin
OpenWriteBuffer;
ClearWriteBuffer;
WriteStream(UpdateFileStream);//发送升级数据流
CloseWriteBuffer;
end;
finally
Disconnect;
UpdateFileStream.Free;
end;
end;
上面程序发送“update”更新命令是用writebuffer(),出错,如果用writeln,接收用readln()就没问题。
能不能在server端TCPSExecute事件里,既能用readln()接收命令,也用readbuffer()接收?