使用 DbgView,我看到在收到 Stream 后,服务器收到 0 个字节,比如 100 多次,这是什么?这对我来说是新的,我从未见过这种情况发生。
我个人觉得这是一个客户端问题,可以吗?
这就是我接收流服务器端的方式:
FMemStream := Socket.ReceiveStream(FMemStreamSize, cbUpdateStreamProgBar);
try
doClientReadStreamEnd;
finally
FMemStream.Free;
FInStreamMode := False; // we're not in stream mode anymore
end;
function TCustomWinSocketHelpher.ReceiveStream(StreamLen: Integer; Callback: TUpdateProgBarProc): TMemoryStream;
const
ChunkSize = 4096; // 4kb
var
PData: PByte;
ReadAmount: Integer;
begin
Result := TMemoryStream.Create;
GetMem(PData, StreamLen);
try
while StreamLen > 0 do
begin
ReadAmount := ReceiveBuf(PData^, ChunkSize);
if (ReadAmount > 0) then
begin
Result.Write(PData^, ReadAmount);
Callback(ReadAmount); // update gui
Inc(PData^, ReadAmount); // update PData current position
Dec(StreamLen, ReadAmount); // update loop condition
end;
end;
finally
FreeMem(PData);
end;
end;
在客户端,这就是我发送流的方式:
FClientSocket.Socket.SendStreamEx(RemoteProcedureCalls.Stream);
procedure TCustomWinSocketHelpher.SendStreamEx(Stream: TStream);
begin
Stream.Seek(0, TSeekOrigin.soBeginning);
SendStream(Stream);
end;
这是它的外观照片,它不应该在第5行之后继续发送。