Least expensive way to know whether connected to internet

Least expensive way to know whether connected to internet

Postby hua » Fri Oct 07, 2011 3:20 am

Hi guys,
If I want to know whether my pc has access to internet or not, would this be the least expensive but still safe way?
Code: Select all  Expand view

   function HasInternetAccess()
      LOCAL pSocket

      INetInit()

      pSocket := INetConnect( "www.google.com", 80 )

      lRet := !empty( INetAddress( pSocket ))

      INetClose( pSocket )
      INetCleanUp()
   RETURN


Thanks for any opinion.

I adapted it from xHarbour's INetAddress() documentation
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: Least expensive way to know whether connected to internet

Postby Bayron » Fri Oct 07, 2011 3:26 am

You can also use function IsInternet():

Code: Select all  Expand view
MsgInfo( IsInternet() )
=====>

Bayron Landaverry
(215)2226600 Philadelphia,PA, USA
+(502)46727275 Guatemala
MayaBuilders@gMail.com

FWH12.04||Harbour 3.2.0 (18754)||BCC6.5||UEstudio 10.10||
Windows 7 Ultimate

FiveWin, One line of code and it's done...
User avatar
Bayron
 
Posts: 815
Joined: Thu Dec 24, 2009 12:46 am
Location: Philadelphia, PA

Re: Least expensive way to know whether connected to internet

Postby hua » Fri Oct 07, 2011 3:34 am

Thanks Bayron. I missed that :) So I'll just use IsInternet()
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Enrico Maria Giordano and 90 guests