BCB6.0 使用IndyTcpClient,IndyTcpServer传输文件问题
客户端像服务器传输视频文件,传输完不能播放,具体用uedit32看了下服务器上的文件开头部分比客户端多写了几个字节,
是不是命令也写进文件了?
还有uedit32查看很多字节都不对应。
服务端代码
void __fastcall TUpLoadServer::IdTCPServer1Execute(TIdPeerThread *AThread){ AnsiString Cmd,FileName; TFileStream* readfile; int FileSize=0; if(!AThread->Connection->Connected()){return;} int recvsize=AThread->Connection->RecvBufferSize; Cmd=AThread->Connection->ReadLn(); //获得命令文件 FileName=TComFun::GetCMDType(Cmd,";"); try { FileSize=StrToInt(TComFun::GetFileSize(Cmd,";")); //获取文件大小 } catch (...) { } if(FileExists(FileName)) { DeleteFile(FileName); } try { readfile=new TFileStream(GetFilePath(FileName),fmCreate); //获得文件路径加上服务器文件夹路径 readfile->Seek(0,soFromBeginning); } catch(...) { } int ASize=0; while (readfile->Position<FileSize) //循环接收文件 { ASize=TComFun::Min(32768,FileSize-readfile->Position); AThread->Connection->ReadStream(readfile,ASize,false); } AThread->Connection->Disconnect(); delete readfile;}