Using IdHTTP I get Error 10054 Connection Reset by Peer

Hi,

I'm trying to get a GIF image from a website every 15 minutes.  But it only works the first time.  At the next attempt (after 15 minutes) I get the error message.  Here is the code :

procedure TForm.Timer1Timer(Sender: TObject);
begin
  GetRadarImage;
end;

procedure TForm.GetRadarImage;
var
  MS : TMemoryStream;
  GIf: TGIFImage;
begin
  MS := TMemoryStream.Create;
  GIf := TGIFImage.Create;
  try
    IdHTTP1.get(RadarURL,MS);
    Ms.Seek(0,soFromBeginning);
    Gif.LoadFromStream(MS);
    Gif.SaveToFile(ExtractFilePath(ParamStr(0))+'radar.tmp');
  finally
    FreeAndNil(GIF);
    FreeAndNil(MS);
  end;
end;

I'm doing something similar on another website to get XML data, and there it works fine.  The only difference between the two http calls is the overloaded method.  In this case I'm using the procedure

procedure Get(AURL: string,AResponseContent: TIdStream); overload;  // this one gives the eror

while in the other case I'm using

function Get(AURL: string): string; overload;  // this one works fine

Should I reset something before calling GET again ?

Thanks,

Soitjes.
0
S
11/24/2010 7:45:04 PM
embarcadero.delphi.winsock 1874 articles. 2 followers. Follow

2 Replies
8851 Views

Similar Articles

[PageSpeed] 53

<S oitjes> wrote in message news:308352@forums.embarcadero.com...

> I'm trying to get a GIF image from a website every 15 minutes.
> But it only works the first time.  At the next attempt (after 15
> minutes) I get the error message.

What do you have the ProtocolVersion property set to?  If pv1_1, then try 
setting it to pv1_0, or alternatively setting the Request.Connection 
connection to 'close' instead.  Either way will tell the server to close the 
connection after sending its response.  For HTTP 1.1 requests, the default 
is 'keep-alive', which will keep the socket open after the response is sent. 
The server is then likely closing the socket on its end after an idle 
timeout, and then TIdHTTP is detecting that on the next request attempt and 
failing to re-connect correctly.

Alternatively, try calling Disconnect() after Get() exits.

Alternatively, destroy the TIdHTTP object and create it each time your timer 
elapses.

> I'm doing something similar on another website to get XML data, and
> there it works fine.  The only difference between the two http calls is
> the overloaded method.  In this case I'm using the procedure
>
> procedure Get(AURL: string,AResponseContent: TIdStream); overload;  // 
> this one gives the eror
>
> while in the other case I'm using
>
> function Get(AURL: string): string; overload;  // this one works fine

All of the Get() (and Post()) overloads go through the same internal method 
for the actual work - DoRequest().  The only difference between the 
overloads is how input and output data is prepared and processed 
before/after TIdHTTP sends a request to the server.

BTW, which version of Indy are you using?  TIdStream has not existed for a 
long time, which makes me think you are using an outdated version and should 
upgrade.

-- 
Remy Lebeau (TeamB)
0
Remy
11/24/2010 8:38:56 PM
Remy,

I tried ProtocolVersion set  to pv1_0, but that didn't make a difference.

Then I tried disconnect right after the get, and that worked.  The error message no longer appears at the next get after 15 minutes.

Thanks very much for you support,

Soitjes.


> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> <S oitjes> wrote in message news:308352@forums.embarcadero.com...
> 
> > I'm trying to get a GIF image from a website every 15 minutes.
> > But it only works the first time.  At the next attempt (after 15
> > minutes) I get the error message.
> 
> What do you have the ProtocolVersion property set to?  If pv1_1, then try 
> setting it to pv1_0, or alternatively setting the Request.Connection 
> connection to 'close' instead.  Either way will tell the server to close the 
> connection after sending its response.  For HTTP 1.1 requests, the default 
> is 'keep-alive', which will keep the socket open after the response is sent. 
> The server is then likely closing the socket on its end after an idle 
> timeout, and then TIdHTTP is detecting that on the next request attempt and 
> failing to re-connect correctly.
> 
> Alternatively, try calling Disconnect() after Get() exits.
> 
> Alternatively, destroy the TIdHTTP object and create it each time your timer 
> elapses.
> 
> > I'm doing something similar on another website to get XML data, and
> > there it works fine.  The only difference between the two http calls is
> > the overloaded method.  In this case I'm using the procedure
> >
> > procedure Get(AURL: string,AResponseContent: TIdStream); overload;  // 
> > this one gives the eror
> >
> > while in the other case I'm using
> >
> > function Get(AURL: string): string; overload;  // this one works fine
> 
> All of the Get() (and Post()) overloads go through the same internal method 
> for the actual work - DoRequest().  The only difference between the 
> overloads is how input and output data is prepared and processed 
> before/after TIdHTTP sends a request to the server.
> 
> BTW, which version of Indy are you using?  TIdStream has not existed for a 
> long time, which makes me think you are using an outdated version and should 
> upgrade.
> 
> -- 
> Remy Lebeau (TeamB)
0
S
11/25/2010 8:13:45 PM
Reply: