Page 1 of 1

Is there a fast way to check online status?

Posted: Thu May 20, 2010 10:06 am
by AlanFoo
Hello ,

I am currently using this to check if I am online...

InitNet=InitNetwork()
resultr= ReceiveHTTPFile("http://www.mywebsite.com/abc.htm", Filename1$)

to see if I get the file. If I dont, it is offline. If I do I know I am online.

Is there a better way or faster way to do this? .. to know if the computer is online?

Thanks

Alan

Re: Is there a fast way to check online status?

Posted: Thu May 20, 2010 10:30 am
by STARGĂ…TE

Code: Select all

Procedure IsOnline(URL$)
  Protected ServerName$ = GetURLPart(URL$, #PB_URL_Site) 
  Protected ConnectionID = OpenNetworkConnection(ServerName$, 80) 
  If ConnectionID 
    CloseNetworkConnection(ConnectionID)
    ProcedureReturn #True
  EndIf 
EndProcedure

InitNetwork()
Debug IsOnline("http://www.google.de/")
Edit: Bugfix

Re: Is there a fast way to check online status?

Posted: Thu May 20, 2010 11:48 am
by AlanFoo
Thanks Stargate.

Alan

Re: Is there a fast way to check online status?

Posted: Thu May 20, 2010 1:18 pm
by jamba
True was being returned for everything I tried so I made a minor modification or two, hope you don't mind :D

Code: Select all

Procedure IsOnline(URL$)
  If FindString(URL$,"http://",1)
    Protected ServerName$ = GetURLPart(URL$, #PB_URL_Site)
  Else
    ServerName$ = URL$
  EndIf
  Debug ServerName$
  If ServerName$ = ""
    ProcedureReturn #False
  EndIf
  
  Protected ConnectionID = OpenNetworkConnection(ServerName$, 80)
  If ConnectionID
    CloseNetworkConnection(ConnectionID)
    ProcedureReturn #True
  EndIf
  ProcedureReturn #False
EndProcedure

InitNetwork()
Debug "Is online: " + Str(IsOnline("74.125.159.106"))
Debug "Is online: " + Str(IsOnline("blahblah"))
Debug "Is online: " + Str(IsOnline("http://www.google.de/"))