关于把文件写入到流中传送的问题
这里是发送文件
var Buf:array[0..BufSize-1] of Char; Sendsize:longint;begin OpenDialog1.Execute; if OpenDialog1.FileName='' then exit; FS:=TFileStream.Create(OpenDialog1.FileName,fmOpenRead); FS.Seek(0,soFromBeginning);{移动指针到流的起始位置} if FS.Size<>0 then begin LeftSize:=FS.Size; while True do begin if LeftSize=0 then begin Break; end else begin if LeftSize<BufSize then begin SendSize:=LeftSize; end else begin Sendsize:=BufSize; end; FS.ReadBuffer(Buf,SendSize); ClientSocket1.Socket.SendBuf(Buf,SendSize); LeftSize:=LeftSize-SendSize; Sleep(10); end; end; end; FS.Free;end; ReceiveLen:=Socket.ReceiveLength; //这里居然等于0,是怎么回事 {接收文件} SaveDialog1.Execute; if SaveDialog1.FileName='' then exit; FS:=TFileStream.Create(SaveDialog1.FileName,fmCreate); FS.Seek(0,soFromBeginning);{移动指针到流的起始位置} Socket.ReceiveBuf(Buf,bufsize); FS.Write(Buf,ReceiveLen); FS.free;