Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2014-10

Detecting if a remote web server is running

8 messages · 6 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

silvioprog
to Richard Mace: What's the most reliable way of detecting whether a remote website is responding? Thanks…
Richard Mace wrote
Hi All, What's the most reliable way of detecting whether a remote website is responding?

Get the HTTP headers:

uses
  fphttpclient;
procedure TForm1.Button1Click(Sender: TObject);
var
  VHttp: TFPHTTPClient;
  VHeaders: TStrings;
begin
  VHttp := TFPHTTPClient.Create(nil);
  VHeaders := TStringList.Create;
  try
    VHttp.RequestHeaders.Add('Connection: Close');
    VHttp.Head('http://lazarus.freepascal.org', VHeaders);
    if VHeaders.Count > 0 then
      ShowMessage('OK')
    else
      ShowMessage('Fail');
  finally
    VHeaders.Free;
    VHttp.Free;
  end;
end;
Silvio Cl?cio My public projects - github.com/silvioprog -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20141030/92cc79f5/attachment.html>

Reply by email

Tony Whyman
to Richard Mace: What's the most reliable way of detecting whether a remote website is responding? Thanks…

Richard,

There is no substitute for "suck it and see". I have a web server that I need to ensure keeps running. I monitor it from another system that runs a CRON job every five minutes that uses "wget" to download the home page. If this fails it EMails me.

As you are putting this on the lazarus list. I assume that you want to do something similar from an interactive Pascal program. Here there is no substitute for good error handling. My experience is with the indy components and these will raise an exception if they can't download a given webpage (timeout). You can catch this and give the user an appropriate error message when they try to access a non-responding server. You could even have a background thread to keep doing this, if it is really important to tell the user as soon as possible.

Tony Whyman
MWA

Richard Mace wrote 14 lines
Hi All, What's the most reliable way of detecting whether a remote website is responding? Thanks Richard -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20141030/3772c5a4/attachment.html>

Reply by email

waldo kitty
to Felipe Monteiro de Carvalho: maybe ping? Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote 6 lines
On Thu, Oct 30, 2014 at 10:44 AM, Richard Mace wrote: > Hi All, > What's the most reliable way of detecting whether a remote website is > responding? maybe ping?

ping might tell you if the IP address is active but that's all... it won't tell you if the server is running or servicing requests... you have to request something from the server to see if it is servicing requests... the easiest and smallest would be to request the headers (only) from the root...

NOTE: No off-list assistance is given without prior approval. Please *keep mailing list traffic on the list* unless private contact is specifically requested and granted.

Reply by email

silvioprog
to waldo kitty
waldo kitty wrote 16 lines
On 10/30/2014 7:29 AM, Felipe Monteiro de Carvalho wrote: > On Thu, Oct 30, 2014 at 10:44 AM, Richard Mace > wrote: > >> Hi All, >> What's the most reliable way of detecting whether a remote website is >> responding? >> > > > maybe ping? ping might tell you if the IP address is active but that's all... it won't tell you if the server is running or servicing requests... you have to request something from the server to see if it is servicing requests... the easiest and smallest would be to request the headers (only) from the root...

+1

Like this:
http://lists.lazarus.freepascal.org/pipermail/lazarus/2014-October/089112.html

Silvio Cl?cio My public projects - github.com/silvioprog -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20141030/83f222e9/attachment-0001.html>

Reply by email

Richard Mace
to silvioprog

Thanks for everyone's replies, very helpful.

Richard

silvioprog wrote 38 lines
On Thu, Oct 30, 2014 at 11:39 AM, waldo kitty wrote: > On 10/30/2014 7:29 AM, Felipe Monteiro de Carvalho wrote: > >> On Thu, Oct 30, 2014 at 10:44 AM, Richard Mace >> wrote: >> >>> Hi All, >>> What's the most reliable way of detecting whether a remote website is >>> responding? >>> >> > > > maybe ping? > > ping might tell you if the IP address is active but that's all... it > won't tell you if the server is running or servicing requests... you have > to request something from the server to see if it is servicing requests... > the easiest and smallest would be to request the headers (only) from the > root... +1 Like this: http://lists.lazarus.freepascal.org/pipermail/lazarus/2014-October/089112.html -- Silvio Cl?cio My public projects - github.com/silvioprog -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20141030/3fcc6f74/attachment.html>

Reply by email