Is there a fast way to check online status?

Just starting out? Need help? Post your questions and find answers here.
AlanFoo
Enthusiast
Enthusiast
Posts: 172
Joined: Fri Jul 24, 2009 6:24 am
Location: Malaysia

Is there a fast way to check online status?

Post 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
User avatar
STARGÅTE
Addict
Addict
Posts: 2236
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

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

Post 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
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
AlanFoo
Enthusiast
Enthusiast
Posts: 172
Joined: Fri Jul 24, 2009 6:24 am
Location: Malaysia

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

Post by AlanFoo »

Thanks Stargate.

Alan
jamba
Enthusiast
Enthusiast
Posts: 144
Joined: Fri Jan 15, 2010 2:03 pm
Location: Triad, NC
Contact:

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

Post 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/"))
-Jon

Fedora user
But I work with Win7
Post Reply