Jack,

The logic in your WSocketDataAvailable is broken. That's the problem.
You used LineMode which is fine, and you selected double CRLF as end of
line. So you received the complete header into the first OnDataAvailable
event. Then you receive subsequent OnDataAvailable depending on what the
server replies (your lines are defined with double CRLF).

To fix your code, simply add a flag in your TProxySocket class and use it to
ignore anything after header. Here is the code:

procedure TProxyChecker.WSocketDataAvailable(Sender: TObject; ErrCode:
Word);
  var s, Status: String;
  StatusCode: Integer;
begin
  if ErrCode = 0 then
    with TProxySocket(Sender) do begin
      s := ReceiveStr();
      if FHeaderFlag then
        Exit;
      FHeaderFlag := TRUE;
      Log(s);
      CloseDelayed();
      //ShutDown(-1);
      GetHTTPReponseStatusCode(s, StatusCode, Status);
      if StatusCode = 200 then
        AddGoodIP(Host);
    end;
end;


In your GetHTTPReponseStatusCode routine, you should check for valid HTTP
reply in case you connect to a broken server or not a HTTP server.

--
[EMAIL PROTECTED]
http://www.overbyte.be


----- Original Message ----- 
From: "Jack"
To: "Francois Piette" <[EMAIL PROTECTED]>
Sent: Friday, May 20, 2005 10:58 PM
Subject: Re[2]: [twsocket] Receive result of the first ReceiveStr() call
twice -not resolved


> Hello Francois,
>
> Thanks for offering to look at my code.
>
> I zipped the (simplified) project files. Since it's
> small (10KB), I'll just email it to you. Please see attached.
> When you run it, the log window displays some logs.
> Below is what I get. Please notice that I'm getting this
> line twice:
>
> 5/20/2005 4:46:47 PM <html><body><font size="5"
color="#FF0000"><br><b>Access denied due to Proxy+'s Security
settings!</b></font><hr>
> <b>Description:</b> REJECTED - by default (no rule allowed the access)
> <br><b>Request details:</b> HTTPS; 68.38.201.173:63664 ->
192.168.2.36:4480
> <hr><font size="2"><font color="#FF0000">Proxy</font><font
color="#0000FF">+</font> 3.00 (Build #246), Date: Fri, 20 May 2005 16:47:22
GMT</font>
>
> Also, in the end, I'm getting a WSocketBgException. It mentions
> 'size="5"', which is a part of the duplicated string. So I suspect
> it has something to do with the dup string:
>
> 5/20/2005 4:46:47 PM WSocketBgException idx=0 addr=chatsvr.no-ip.org:4480
Exception='size="5"' is not a valid integer value
>
> The IP I'm connecting to (chatsvr.no-ip.org) is a proxy server
> I set up for testing using commercial proxy server ProxyPlus.
> The client IP is disallowed so that the application will get
> a longer HTTP reply in order to reproduce this problem.
>
> -- 
> Best regards,
> Jack
>
>
> 5/20/2005 4:46:47 PM GetIP: chatsvr.no-ip.org:4480
> 5/20/2005 4:46:47 PM HTTP/1.0 403 Forbidden
> Date: Fri, 20 May 2005 20:47:22 GMT
> Content-Type: text/html
> Content-Length: 1213
>
>
> 5/20/2005 4:46:47 PM <html><body><font size="5"
color="#FF0000"><br><b>Access denied due to Proxy+'s Security
settings!</b></font><hr>
> <b>Description:</b> REJECTED - by default (no rule allowed the access)
> <br><b>Request details:</b> HTTPS; 68.38.201.173:63664 ->
192.168.2.36:4480
> <hr><font size="2"><font color="#FF0000">Proxy</font><font
color="#0000FF">+</font> 3.00 (Build #246), Date: Fri, 20 May 2005 16:47:22
GMT</font>
>
>
> 5/20/2005 4:46:47 PM <html><body><font size="5"
color="#FF0000"><br><b>Access denied due to Proxy+'s Security
settings!</b></font><hr>
> <b>Description:</b> REJECTED - by default (no rule allowed the access)
> <br><b>Request details:</b> HTTPS; 68.38.201.173:63664 ->
192.168.2.36:4480
> <hr><font size="2"><font color="#FF0000">Proxy</font><font
color="#0000FF">+</font> 3.00 (Build #246), Date: Fri, 20 May 2005 16:47:22
GMT</font>
>
> <br><br>
> <!--
> <hr>MS IE 5.X replaces error messages when the message is too short!<br>
> Note: If you see this text it is due to MS IE bug with HTTPS error
responses.<br>
> <br>
> The message has to be larger than 512 bytes...<br>
> <br>
> **************************************************************<br>
> **************************************************************<br>
> **************************************************************<br>
> **************************************************************<br>
> **************************************************************<br>
> **************************************************************<br>
> **************************************************************<br>
> **************************************************************<br>
>
> -->
> </body></html>
>
> 5/20/2005 4:46:47 PM WSocketBgException idx=0 addr=chatsvr.no-ip.org:4480
Exception='size="5"' is not a valid integer value
>
>
> Friday, May 20, 2005, 3:50:18 AM, you wrote:
>
> FP> I still persist saying the you probably call the message pump
> FP> directly or indirectly (for example
> FP> your Log() function, or any component you use for display).
> FP> I suggest you make a stripped down version of your program,
> FP> just he bare minimum in a small project.
> FP> If the problem persist with this small project, make it
> FP> available for download somewhere. If I have
> FP> time, I'll look at it.
>
> FP> --
> FP> Contribute to the SSL Effort. Visit
> FP> http://www.overbyte.be/eng/ssl.html
> FP> --
> FP> [EMAIL PROTECTED]
> FP> Author of ICS (Internet Component Suite, freeware)
> FP> Author of MidWare (Multi-tier framework, freeware)
> FP> http://www.overbyte.be
>
>
> FP> ----- Original Message ----- 
> FP> From: "Jack" <[EMAIL PROTECTED]>
> FP> To: "ICS support mailing" <twsocket@elists.org>
> FP> Sent: Thursday, May 19, 2005 9:31 PM
> FP> Subject: [twsocket] Receive result of the first ReceiveStr() call
twice -not resolved
>
>
> >> I celebrated a little too early. I am getting this problem again
> >> in further testing after I changed Close() to CloseDelayed();
> >> The difference is, I'm not getting result of the first ReceiveStr()
> >> twice. Instead, I get the result of the second ReceiveStr() twice.
> >> I think this is because CloseDelayed() delayed the Close().
> >> What I don't understand is why the buffer isn't cleared after
> >> ReceiveStr() in both scenarios of Close() and CloseDelayed().
> >>
> >> I reason I thought it was fixed is because I tested from
> >> an allowed IP earlier and got a very short response back from
> >> the proxy server. The whole message was retrieved in the first
> >> ReceiveStr() call so I didn't get a chance to call ReceiveStr()
> >> twice. I then run the same app on a blocked IP. The proxy sends
> >> a longer message (the error message) and it is retrieved in
> >> two ReceiveStr() calls. Then I found that the second ReceiveStr()
> >> result was duplicated.
> >>
> >> -- 
> >> Best regards,
> >> Jack
> >>
> >> Thursday, May 19, 2005, 10:53:49 AM, you wrote:
> >>
> >> J> Francois, thanks! This fixed the problem! It's actually in the FAQ:
> >>
> >> J> - CloseDelayed
> >>
> >> J> Is in most cases the preferred way. It will post a message to
> >> J> itself to close the TWSocket. This means that the socket closure
> >> J> is done outside the code that calls the CloseDelayed, meaning a
> >> J> while later. The message handler will call Close.
> >>
> >> J> - Close
> >>
> >> J> Attempt to gracefully close the socket. If there is still some
> >> J> data waiting in the buffers it will try to send it. ***Do not use
> >> J> Close from within any TWSocket events, instead use CloseDelayed.***
> >>
> >>
> >> J> Thursday, May 19, 2005, 2:46:47 AM, you wrote:
> >>
> >> FP>> Use CloseDelayed instead of Close.
> >>
> >> >>> Hello Wilfried,
> >> >>>
> >> >>> Sure. Below is my event handler code. Hope I'm doing something
> >> >>> wrong, otherwise, it's really strange. TProxyChecker is the owner
> >> >>> object of the TProxySocket object array. TProxySocket is derived
> >> >>> from TWSocket.
> >> >>>
> >> >>> procedure TProxyChecker.WSocketDataAvailable(Sender: TObject;
ErrCode: Word);
> >> >>> var s: String;
> >> >>> begin
> >> >>>   if ErrCode = 0 then
> >> >>>     with TProxySocket(Sender) do
> >> >>>     begin
> >> >>>       s := ReceiveStr();
> >> >>>       Log(s);
> >> >>>       Close();
> >> >>>     end;
> >> >>> end;
> >> >>>
> >> >>> The destination server is a commercial http proxy server.
> >> >>> I tried using #13#10 and #13#10#13#10, I different strings
> >> >>> read back from ReceiveStr. But the second string includes
> >> >>> the first string in both cases. So it shouldn't be the server
> >> >>> sending the string twice.
> >> >>>
> >> >>> BTW, I'm using the latest ICS.
> >> >>>
> >> >>> -- 
> >> >>> Best regards,
> >> >>> Jack
> >> >>>
> >> >>> Wednesday, May 18, 2005, 3:31:32 PM, you wrote:
> >> >>>
> >> >>> WM> Hello Jack,
> >> >>>
> >> >>> WM> Can you show your OnDataAvailable handler ?
> >> >>> WM> Eventually download SocketSpy from 'user made' page and 'hang'
it
> >> >>> WM> between client and server. Then you see exacly what is sent by
server.
> >> >>>
> >> >>> WM> ---
> >> >>> WM> Rgds, Wilfried
> >> >>> WM> http://www.mestdagh.biz
> >> >>>
> >> >>> WM> Wednesday, May 18, 2005, 20:48, Jack wrote:
> >> >>>
> >> >>> >> Hello Francois and all,
> >> >>>
> >> >>> >> I'm using a TWSocket client in LineMode with LineEnd set to
#13#10.
> >> >>> >> I connect to a HTTP proxy server using CONNECT command. I then
get
> >> >>> >> a reply back from the HTTP proxy from ReceiveStr()
> >> >>>
> >> >>> >> Things look OK except that I am receiving the data from the
first
> >> >>> >> ReceiveStr() call twice. I get two WSocketDataAvailable messages
for
> >> >>> >> 3 lines in the HTTP response:
> >> >>>
> >> >>> >>   Line 1: HTTP/1.0 200 Connection established
> >> >>> >>   Line 2: Proxy-agent: Proxy+ 3.00
> >> >>> >>   Line 3: (Blank line)
> >> >>>
> >> >>> >> However, I'm getting the first ReceiveStr() result twice, see
below:
> >> >>> >> I'm getting "HTTP/1.0 200 Connection established" twice:
> >> >>>
> >> >>> >> 5/18/2005 2:36:43 PM WSocketDataAvailable idx=0
addr=127.0.0.1:4480 ErrCode=0
> >> >>> >> 5/18/2005 2:36:43 PM HTTP/1.0 200 Connection established
> >> >>> >> 5/18/2005 2:36:43 PM
> >> >>> >> 5/18/2005 2:36:43 PM
> >> >>> >> 5/18/2005 2:36:43 PM WSocketDataAvailable idx=0
addr=127.0.0.1:4480 ErrCode=0
> >> >>> >> 5/18/2005 2:36:43 PM HTTP/1.0 200 Connection established
> >> >>> >> Proxy-agent: Proxy+ 3.00
> >> >>>
> >> >>>
> >> >>> >> I then changed LineEnd to #13#10#13#10, I still get the result
of
> >> >>> >> the first ReceiveStr() twice, this time the result is two lines:
> >> >>>
> >> >>> >>   HTTP/1.0 200 Connection established
> >> >>> >>   Proxy-agent: Proxy+ 3.00
> >> >>> >>   (Blank line)
> >> >>>
> >> >>> >> 5/18/2005 2:40:11 PM WSocketDataAvailable idx=0
addr=127.0.0.1:4480 ErrCode=0
> >> >>> >> 5/18/2005 2:40:11 PM HTTP/1.0 200 Connection established
> >> >>> >> Proxy-agent: Proxy+ 3.00
> >> >>>
> >> >>>
> >> >>> >> 5/18/2005 2:40:11 PM
> >> >>> >> 5/18/2005 2:40:11 PM
> >> >>> >> 5/18/2005 2:40:11 PM WSocketDataAvailable idx=0
addr=127.0.0.1:4480 ErrCode=0
> >> >>> >> 5/18/2005 2:40:11 PM HTTP/1.0 200 Connection established
> >> >>> >> Proxy-agent: Proxy+ 3.00
> >> >>>
> >> >>>
> >> >>> >> It seems that, somehow the first ReceiveStr() didn't remove the
data
> >> >>> >> from the buffer. Or am I missing anything?
> >> >>>
> >> >>>
> >> >>> >> -- 
> >> >>> >> Best regards,
> >> >>> >> Jack
> >> >>>
> >> >>>
> >> >>>
> >> >>>
> >> >>>
> >> >>>
> >> >>> -- 
> >> >>> To unsubscribe or change your settings for TWSocket mailing list
> >> >>> please goto http://www.elists.org/mailman/listinfo/twsocket
> >> >>> Visit our website at http://www.overbyte.be
> >> >>>
> >>
> >>
> >>
> >>
> >>
> >> -- 
> >> To unsubscribe or change your settings for TWSocket mailing list
> >> please goto http://www.elists.org/mailman/listinfo/twsocket
> >> Visit our website at http://www.overbyte.be
> >>
>
>


-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to