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. )
> {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...
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.
> {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...
> {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
> {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}
> {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...