Board index » delphi » A question about Indy

A question about Indy


2003-09-02 10:48:55 PM
delphi134
How can I check (using Indy) if there is connection established to the Internet?
I want my application to check if there is a connection to the Internet before it tries anything...
Thanx,
Nikola
 
 

Re:A question about Indy

Nikola writes:
Quote

How can I check (using Indy) if there is connection established to
the Internet? I want my application to check if there is a
connection to the Internet before it tries anything...


what does "connected to the internet" mean?
it's not a simple answer
Grahame
 

Re:A question about Indy

In borland.public.delphi.internet.winsock, Nikola <XXXX@XXXXX.COM>wrote
in message <3f54add7$XXXX@XXXXX.COM>...
Quote
How can I check (using Indy) if there is connection established to the Internet?
I want my application to check if there is a connection to the Internet before it tries anything...
I would like to humbly suggest that it might be better to redesign your app
in such a way that it doesn't need to know ahead of time whether or not there
is a connection. I will give you an example. I have written a newsgroup reader
(still tidying up loose ends so it isn't available yet) that can operate as
an offline reader if there is no connection. The way this works is quite
simple. It uses queues for upload and download requests and these queues are
only loosely coupled to the other processes. They periodically try to
send/receive and if there is a failure it sends the item to the back of the
queue and goes on to the next one. This all happens in a secondary thread so
the GUI is not bogged down. If there is no connection, these queues simply
quietly cycle through their items, attempting each one and quietly requeuing
it when it fails. When there is finally a connection, these queues will
succeed in trying to upload/download their items. No need to have an offlne
mode and an online mode. (Of course the user has the option of stopping the
timer that instigates each retry, if they don't want it continually cycling
like that.)
 

Re:A question about Indy

Nikola writes:
Quote
How can I check (using Indy) if there is connection established to
the Internet? I want my application to check if there is a
connection to the Internet before it tries anything...
try
IdHttp.Get('www.microsoft.com');
ShowMessage('Is connected');
except
ShowMessage('Is not connected');
end;
Quick and dirty solution. You can use an URL that points to a site that
just returns a short string of course, instead of a voluminous site like
microsoft.com
--
Ingvar Nilsen
 

Re:A question about Indy

You have to be very careful when checking for an active connection, as
probing or requesting a connection to a remote server can cause a lot of
dial on demand routers to dial up, and many people do not like this
(especially if they pay by the minute and are using ISDN, and you
application keeps trying every 5 minutes ;))
Andy
Nikola writes:
Quote
How can I check (using Indy) if there is connection established to the Internet?
I want my application to check if there is a connection to the Internet before it tries anything...



Thanx,

Nikola
 

Re:A question about Indy

"Nikola" <XXXX@XXXXX.COM>writes
Quote
How can I check (using Indy) if there is connection
established to the Internet?
The only thing Indy natively has available for that is the TIdIPWatch
compoent. Whenever the TIdIPWatch component returns an IP address of
"127.0.0.1" or "", then you are considered offline. It also was an
IsOnline() method that does the checking internally for you.
Gambit
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (www.grisoft.com).
Version: 6.0.515 / Virus Database: 313 - Release Date: 9/1/03
 

Re:A question about Indy

Remy Lebeau (TeamB) writes:
Quote
The only thing Indy natively has available for that is the TIdIPWatch
compoent. Whenever the TIdIPWatch component returns an IP address of
Quote
"127.0.0.1" or "", then you are considered offline. It also was an
IsOnline() method that does the checking internally for you.
Will this work with the computer connected to a LAN? Probably not?
Even at my home office, with 3 machines connected in a peer network, as
long as the others are on, I don't think it will return "127.0.0.1"
even when disconnected from the Internet.
--
Ingvar Nilsen
 

Re:A question about Indy

"Ingvar Nilsen" <telcontr@[Remove-This-Part]online.no>writes
Quote
Will this work with the computer connected to a LAN?
It will tell you if the machine has an IP address, but that does not
necessary mean that the machine is connected to the internet. If the LAN
uses a DHCP, than maybe it might work. But not if it uses a static IP
instead.
Gambit
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (www.grisoft.com).
Version: 6.0.515 / Virus Database: 313 - Release Date: 9/1/03
 

Re:A question about Indy

Captain Jake writes:
Quote
In borland.public.delphi.internet.winsock, Ingvar Nilsen
<telcontr@[Remove-This-Part]online.no>writes
<XXXX@XXXXX.COM>...
>
>try
>IdHttp.Get('www.microsoft.com');
>ShowMessage('Is connected');
>except
>ShowMessage('Is not connected');
>end;
>
>Quick and dirty solution. You can use an URL that points to a site
>that just returns a short string of course, instead of a voluminous
>site like microsoft.com

Why not just ping the site?
Microsoft's site doesn't respond to pings, I think.
Cheers,
Nicholas Sherlock
 

Re:A question about Indy

"Nicholas Sherlock" <XXXX@XXXXX.COM>writes
Quote
Microsoft's site doesn't respond to pings, I think.
Sure, it does:
C:\WINDOWS>ping www.microsoft.com
Pinging a562.cd.akamai.net [207.126.99.159] with 32 bytes of data:
Reply from 207.126.99.159: bytes=32 time=79ms TTL=240
Reply from 207.126.99.159: bytes=32 time=81ms TTL=240
Reply from 207.126.99.159: bytes=32 time=81ms TTL=240
Reply from 207.126.99.159: bytes=32 time=81ms TTL=240
Gambit
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (www.grisoft.com).
Version: 6.0.515 / Virus Database: 313 - Release Date: 9/2/03
 

Re:A question about Indy

Quote
Sure, it does:
True, but they used to block pings.
Don't know why they allow them now.
 

Re:A question about Indy

It's simple really.
Just call the connect procedure and have a timeout of 5 seconds, if it times
out then you have no connection.
try
myclient.connect(5000); //if it times out exception will occur and you
can trap it.
except
end;
"Nikola" <XXXX@XXXXX.COM>writes
Quote

How can I check (using Indy) if there is connection established to the
Internet?
I want my application to check if there is a connection to the Internet
before it tries anything...



Thanx,

Nikola
 

Re:A question about Indy

Quote
It's simple really.
The problem with this way is, that it might trigger a dial-up
connection, or a router to establish a connection.
If you can accept this, it is ok, otherwise this won't work because it
is not guaranteed *not* to trigger such a connection.
Andy
 

Re:A question about Indy

In borland.public.delphi.internet.winsock, Captain Jake
<"johnj[nospam]"@comcast.net>writes
<XXXX@XXXXX.COM>...
Quote
Why not just ping the site?
Actually, I can not ping ANYTHING from work, but have internet access.
 

Re:A question about Indy

"Captain Jake" <johnj[nospam]@comcast.net>writes
Quote
Actually, I can not ping ANYTHING from work, but have internet access.
Maybe your office firewall is blocking pings?
Gambit
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (www.grisoft.com).
Version: 6.0.515 / Virus Database: 313 - Release Date: 9/1/03