How to check if I have an internet connection

Previous topic - Next topic

Millerszone

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
Hardware: iMac 27", MacBook Air, PC 3.5Ghz Quad
Developing Tools: GLBasic SDK, Gideros Studio, PureBasic
Developing for: iOS, Android, Windows, OS X, webOS, HTML5

Millerszone

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.

Hardware: iMac 27", MacBook Air, PC 3.5Ghz Quad
Developing Tools: GLBasic SDK, Gideros Studio, PureBasic
Developing for: iOS, Android, Windows, OS X, webOS, HTML5

ampos

That's because if you try to open an unexistent web, the Internet returns a Pagd not found error
check my web and/or my blog :D
http://diniplay.blogspot.com (devblog)
http://www.ampostata.org
http://ampostata.blogspot.com
I own PC-Win, MacBook 13", iPhone 3G/3GS/4G and iPAC-WinCE

MrTAToad

Best way would be some sort of PING utility to a site that wont disappear.

Moru

No way of doing a normal ping in glbasic, mabe open a tcp port 80 to google or something :-)

Kitty Hello

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


Millerszone

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.
Hardware: iMac 27", MacBook Air, PC 3.5Ghz Quad
Developing Tools: GLBasic SDK, Gideros Studio, PureBasic
Developing for: iOS, Android, Windows, OS X, webOS, HTML5

MrTAToad

QuoteBut what if google.com goes down?  just kidding.
Would be best to check against three or so different addresses

Kitty Hello

-google
-microsoft
-glbasic
- the big 3 :D

Ian Price

How can you not put GLBasic first Gernot? :P :D
I came. I saw. I played.