用Indy 9 的TIdMappedPortTCP控件做代理服务器,丢数据
我做了一个代理服务器程序,接收来自客户端的Post数据,并且转发,用Indy 9 的TIdMappedPortTCP控件,其中有如下函数,接收客户端数据:
function TFormMain.ReceiveData(Athread: TIdMappedPortThread): Boolean;
{获取来自客户机的请求数据,将数据直接保存到Athread.NetData}
begin
with Athread do
begin
NetData:='';
result:=False;
try
Connection.ReadFromStack(true,-1,true);
NetData:=Connection.InputBuffer.Extract(Connection.InputBuffer.Size);
result:=true;
except
end;
end;
end;
问题是,在Post数据比较大的时候,经常丢数据,比如Http头中的Content-Length: 57040
但实际得到的数据也许只有8000多,有时候是3000多,这是怎么回事呢?Indy的源代码我看了,具体如何读缓冲区的部分就不懂了,请高手们指教。