Mega Search
23.2 Million


Sign Up

Make a donation  
TidHTTP and response timeout [Edit]  
News Group: embarcadero.public.delphi.internet.winsock

Delphi 2010 Prof.
Indy 10.5.5
========

Hello,

I have been looking for this in google and in the indyInDepth book, but I have not
found anything useful (or I could understand).

I have to get an image from a web server (http) and I am using a
function I found on some place.

Ok, in summary, I use this:


{code}    try
      idHttp.Get(URL, imgStream);
    finally
      idHttp.Free;
    end;
{code}

but if idHttp client has no answer at all, then there is no timeout or the
timeout parameter:
 {code} idHttp.ReadTimeout {code}
doesn't run as I am expected.

How can I set a real timeout to the idHttp client ?

Thanks.

PS: I have send the same question in Atozed Newsgroup.

Edited by: Terry Yapt on Oct 22, 2010 6:22 AM  ( Delphi and Indy versions added. )

Vote for best question.
Score: 0  # Vote:  0
Date Posted: 22-Oct-2010, at 9:23 AM EST
From: Terry Yapt
 
Re: TidHTTP and response timeout [Edit]  
News Group: embarcadero.public.delphi.internet.winsock
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
>  wrote in message news:299566@forums.embarcadero.com...
> 
> > if idHttp client has no answer at all, then there is no timeout or the
> > timeout parameter:
> > {code} idHttp.ReadTimeout {code}
> > doesn't run as I am expected.
> 
> Works fine for me.

It runs fine for you with Get Method ?
{code}
  try
    idHttp := TIdHTTP.Create(nil);
    idHttp.ConnectTimeout := 3000; // 3 seconds
    idHttp.ReadTimeout    := 2000;  // 2 seconds
    try
       idHttp.Get(URL, imgStream);  // <<-------  This ¿?¿?¿
    finally
      idHttp.Free;   // Never get into this...
    end;
{code}

Thanks Remy...

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 22-Oct-2010, at 1:19 PM EST
From: Terry Yapt
 
Re: TidHTTP and response timeout [Edit]  
News Group: embarcadero.public.delphi.internet.winsock
Hi,

Could you tell me how to catch the IDHttp timeout Exception... and which exception in your example above... ?

I need it to make more try if the first connexion fails.

{code}
    try
        IdHTTP1.Post(url, stl, ts);
    except
     ...
   end;
{code}



Cédric

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 28-Jul-2011, at 4:22 PM EST
From: cedric joubert
 
Re: TidHTTP and response timeout [Edit]  
News Group: embarcadero.public.delphi.internet.winsock
hum... i don't know which one... but thoses catched when then TIdHttp seems to reach a very slow site.
Even the query can return with success, i would need to abort in the next 3 sec for example...

How would you implement this kind of behavious please ?

Cédric

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 29-Jul-2011, at 4:17 PM EST
From: cedric joubert
 
Re: TidHTTP and response timeout [Edit]  
News Group: embarcadero.public.delphi.internet.winsock
My problem is another than I was thinking....   :-(

In my tests I was trying several WebCam's and I got into this one:
http://202.213.157.230/nphMotionJpeg?Resolution=640x480&Quality=Standard

But this is a "continuous jpeg image" (load in your explorer to know what I say), then I suppose it NEVER stops sending information.  So idHttp component never goes into the next line.

Ok, I must to change my question:
How can I stop my idHttp.Get (raise exception) based in size or time ?

Thanks.

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 22-Oct-2010, at 1:24 PM EST
From: Terry Yapt
 
Re: TidHTTP and response timeout [Edit]  
News Group: embarcadero.public.delphi.internet.winsock
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
>  wrote in message news:299634@forums.embarcadero.com...
> 
> > In my tests I was trying several WebCam's and I got into this one:
> > http://202.213.157.230/nphMotionJpeg?Resolution=640x480&Quality=Standard
> >
> > But this is a "continuous jpeg image" (load in your explorer to know what 
> > I say)
> 
> When I load that URL in IE8, it tries to download a file of unknown format, 
> not display a "continuous" image.  The webserver is sending the data as a 
> "multipart/x-mixed-replace" Content-Type, which IE does not support.

You are right, IE8 tries to download a file.  Firefox runs fine and show me an office or something similar.  It is a "public" webcam I got searching on google.

> 
> > I suppose it NEVER stops sending information.  So idHttp component never
> > goes into the next line.
> 
> That is correct.  The webserver is not sending either a "Content-Length: 
> ..." or "Transfer-Encoding: chunked" header, so TIdHTTP has no choice but to 
> wait until the server closes the connection to signal the end of the data. 
> The "multipart/x-mixed-replace" type is designed to not close the connection 
> until the end of the data stream has been reached (for a streaming video 
> file), however a live stream (like a webcam) will never end, so 
> TIdHTTP.Get() will read indefinately (unless it times out if ReadTimeout is 
> set) until the connection is closed.

Thanks for your complete explanation.

> 
> > How can I stop my idHttp.Get (raise exception) based in size or time ?
> 
> You can either Disconnect() it from a separate thread when needed, or you 
> can implements a custom TStream class that raises an exception in its 
> overriden Write() method.
> 
> To handle "multipart/x-mixed-replace" responses with TIdHTTP, you are better 
> off using the TStream approach.  That way, you can manually detect when each 
> MIME boundary arrives and then process each data block as needed while Get() 
> is still running.  Maybe in a future version of Indy, TIdHTTP will implement 
> native support for "multipart/x-mixed-replace" responses.
> 
> Otherwise, you will have to switch your code to use TIdTCPClient directly, 
> and then implement the HTTP processing manually.

I think I will try the TStream approach but now it is not so important because my concern was a good server without an answer not a bad server configuration.  :-\

Thanks for your help Remy and also for the answers from the other people.

Best regards...

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 22-Oct-2010, at 4:01 PM EST
From: Terry Yapt
 
Re: TidHTTP and response timeout  
News Group: embarcadero.public.delphi.internet.winsock
> {quote:title=Terry Yapt wrote:}{quote}
> Delphi 2010 Prof.
> Indy 10.5.5
> ========
> 
> Hello,
> 
> I have been looking for this in google and in the indyInDepth book, but I have not
> found anything useful (or I could understand).
> 
> I have to get an image from a web server (http) and I am using a
> function I found on some place.
> 
> Ok, in summary, I use this:
> 
> 
> {code}    try
>       idHttp.Get(URL, imgStream);
>     finally
>       idHttp.Free;
>     end;
> {code}
> 
> but if idHttp client has no answer at all, then there is no timeout or the
> timeout parameter:
>  {code} idHttp.ReadTimeout {code}
> doesn't run as I am expected.
> 
> How can I set a real timeout to the idHttp client ?
> 
> Thanks.
> 
> PS: I have send the same question in Atozed Newsgroup.
> 
> Edited by: Terry Yapt on Oct 22, 2010 6:22 AM  ( Delphi and Indy versions added. )

Please try:
idHTTP.IOHandler.ReadTimeout

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 22-Oct-2010, at 11:42 AM EST
From: Hafedh TRIMECHE
 
Re: TidHTTP and response timeout  
News Group: embarcadero.public.delphi.internet.winsock
> {quote:title=Hafedh TRIMECHE wrote:}{quote}
> > {quote:title=Terry Yapt wrote:}{quote}
> > Delphi 2010 Prof.
> > Indy 10.5.5
> > ========
> > 
> > Hello,
> > 
> > I have been looking for this in google and in the indyInDepth book, but I have not
> > found anything useful (or I could understand).
> > 
> > I have to get an image from a web server (http) and I am using a
> > function I found on some place.
> > 
> > Ok, in summary, I use this:
> > 
> > 
> > {code}    try
> >       idHttp.Get(URL, imgStream);
> >     finally
> >       idHttp.Free;
> >     end;
> > {code}
> > 
> > but if idHttp client has no answer at all, then there is no timeout or the
> > timeout parameter:
> >  {code} idHttp.ReadTimeout {code}
> > doesn't run as I am expected.
> > 
> > How can I set a real timeout to the idHttp client ?
> > 
> > Thanks.
> > 
> > PS: I have send the same question in Atozed Newsgroup.
> > 
> > Edited by: Terry Yapt on Oct 22, 2010 6:22 AM  ( Delphi and Indy versions added. )
> 
> Please try:
> idHTTP.IOHandler.ReadTimeout

Where could I put the idHTTP.IOHandler.ReadTimeOut inside this code ?

{code}
function DownloadJPGToBitmap(const URL: string; ABitmap: TBitmap): Boolean;
var
  idHttp   :  TIdHTTP;
  imgStream: TMemoryStream;
  jpgImage : TJPEGImage;
begin
  result := false;
  imgStream := TMemoryStream.Create;
  try
    idHttp := TIdHTTP.Create(nil);
    idHttp.ConnectTimeout := 3000;
    try
      idHttp.Get(URL, imgStream);
    finally
      idHttp.Free;
    end;
    imgStream.Position := 0;
    jpgImage := TJPEGImage.Create;
    try
      jpgImage.LoadFromStream(imgStream);
      ABitmap.Assign(jpgImage);
      result := True;
    finally
      jpgImage.Free;
    end;
  finally
    imgStream.Free;
  end;
end;
{code}

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 22-Oct-2010, at 11:53 AM EST
From: Terry Yapt
 
Re: TidHTTP and response timeout [Edit]  
News Group: embarcadero.public.delphi.internet.winsock
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
>  wrote in message news:299631@forums.embarcadero.com...
> 
> > It runs fine for you with Get Method ?
> 
> Yes.

Thanks Remy...

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 22-Oct-2010, at 3:56 PM EST
From: Terry Yapt
 
Re: TidHTTP and response timeout [Edit] [Edit]  
News Group: embarcadero.public.delphi.internet.winsock
Thanks Remy,

In fact, i'm probably missing something in my code, because i've never seen any exception raised on my appli.
or maybe i'm just lucky with all the sites which i connect.

The only 2 exceptions i can simulate is these ones :
-  (disabling my lan connection before connecting)
Socket Error (11004)

- Connect to a site i've found with google  by chance (i do not know it) that do not respond
http://www.313fad.com
Socket Error (Host not found - 11001)

Maybe do you know any good benchmark site i can connect to test differents scenarios (to test slow connection but site alive)... ?

Oups...(i'm re-editing this messageI ;-)  )  I'm realising... that I did not configure the ReadTimeout property... Si i have a to test it before... (and I come back)

Cédric

Edited by: cedric joubert on Jul 30, 2011 1:03 AM

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 30-Jul-2011, at 4:05 AM EST
From: cedric joubert