Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 May : Re: TIdTCPClient, TIdIOHandler and a Headache
| Subject: | Re: TIdTCPClient, TIdIOHandler and a Headache |
| Posted by: | "Remy Lebeau (TeamB)" (no.spam@no.spam.com) |
| Date: | Mon, 29 May 2006 16:19:38 |
"Lloyd Kinsella" <lloydkinsella@gmail.com> wrote in message
news:447b665f@newsgroups.borland.com...
> I am using my own, I'm using TIdCmdTCPServer like the proxy
> component does, I was just stating how TIdHTTPProxy does it.
> My issue is HOW to implement the send-as-it-captures
You need to use ReadBytes/Write(Bytes) instead of ReadStream/Write(Stream).
> as the code I gave doesn't work
You did not show WHERE that code is being called from. You are also doing
blocking reads on MaxBufSize packets, which makes the code block if smaller
packets are received. You should be taking into account the actual size of
the packets being received instead. For example:
var
DataSize: Int64;
begin
// send request to target server ...
// read headers ...
If (The Data Size Is Specified) then
begin
DataSize := (The Specified Data Size Here);
while DataSize > 0 do
begin
SetLength(Buffer, Max(DataSize, MaxBufSize));
Client.IOHandler.ReadBytes(Buffer, Length(Buffer), False);
ASender.Context.Connection.IOHandler.Write(Buffer);
Dec(DataSize, Length(Buffer));
end;
end else
begin
while Client.Connected do
begin
if Client.IOHandler.InputBuffer.Size < MaxBufSize then
Client.IOHandler.CheckForDataOnSource(1000);
if Client.IOHandler.InputBuffer.Size > 0 then
begin
DataSize := Max(Client.IOHandler.InputBuffer.Size,
MaxBufSize);
SetLength(Buffer, DataSize);
Client.IOHandler.InputBuffer.ExtractToBytes(Buffer,
DataSize, False);
ASender.Context.Connection.IOHandler.Write(Buffer);
end;
end;
end;
end;
> it's not that TIdHTTPProxy doesn't support it
TIdHTTPProxyServer does not support it at all, period. It is strictly a
capture-all-and-then-send component, which is not what you are asking for.
Gambit