GLBasic forum

Main forum => GLBasic - en => Topic started by: Millerszone on 2011-Jan-19

Title: How to check if I have an internet connection
Post by: Millerszone on 2011-Jan-19
I'm trying to check to see if I have an internet connection or not.

Using the code below, I thought "ok" would be 0 if I didn't have an internet connection or the
web site was down.

ok = NETWEBGET("upperdeck.host-ed.net", str$, 80, "leaderboard.dat")
PRINT ok, 10,10

"ok" is always 1, even if I change the name of the server to a non-existing server.

any suggestions?
thanks
Mike
Title: Re: How to check if I have an internet connection
Post by: Millerszone on 2011-Jan-19
Quote from: millerszone on 2011-Jan-19
I'm trying to check to see if I have an internet connection or not.

Using the code below, I thought "ok" would be 0 if I didn't have an internet connection or the
web site was down.

ok = NETWEBGET("upperdeck.host-ed.net", str$, 80, "leaderboard.dat")
PRINT ok, 10,10

"ok" is always 1, even if I change the name of the server to a non-existing server.

To test I was just changing the server name.. (example: "upperdeck.host-ed.net to upperdeck.net)
but was getting ok=1, but if I disable my network card or leave the server name blank, then I get a ok=0.
Fixed now.

Title: Re: How to check if I have an internet connection
Post by: ampos on 2011-Jan-19
That's because if you try to open an unexistent web, the Internet returns a Pagd not found error
Title: Re: How to check if I have an internet connection
Post by: MrTAToad on 2011-Jan-19
Best way would be some sort of PING utility to a site that wont disappear.
Title: Re: How to check if I have an internet connection
Post by: Moru on 2011-Jan-20
No way of doing a normal ping in glbasic, mabe open a tcp port 80 to google or something :-)
Title: Re: How to check if I have an internet connection
Post by: Kitty Hello on 2011-Jan-20
right. Something like:
Code (glbasic) Select

SOCK_INIT
sock% = SOCK_TCP_CONENCT("ww.google.com", 80)
IF sock>0 THEN bInternet=TRUE // check return value. Is it 0 or -1 on error?
SOCK_CLOSE(sock)
SOCK_SHUTDOWN

Title: Re: How to check if I have an internet connection
Post by: Millerszone on 2011-Jan-20
Quote from: Kitty Hello on 2011-Jan-20
right. Something like:
Code (glbasic) Select

SOCK_INIT
sock% = SOCK_TCP_CONENCT("www.google.com", 80)
IF sock>0 THEN bInternet=TRUE // check return value. Is it 0 or -1 on error?
SOCK_CLOSE(sock)
SOCK_SHUTDOWN


But what if google.com goes down?  just kidding.

Works perfect, thanks.
Title: Re: How to check if I have an internet connection
Post by: MrTAToad on 2011-Jan-20
QuoteBut what if google.com goes down?  just kidding.
Would be best to check against three or so different addresses
Title: Re: How to check if I have an internet connection
Post by: Kitty Hello on 2011-Jan-21
-google
-microsoft
-glbasic
- the big 3 :D
Title: Re: How to check if I have an internet connection
Post by: Ian Price on 2011-Jan-21
How can you not put GLBasic first Gernot? :P :D