• HomeBoards
  • RulesRules
  • HelpHelp
  • WikiWiki
  • Donate

Author Topic: (Internet) Connection available?  (Read 3485 times)

Ziz (OP)

  • Posts: 285
    • http://ziz.gp2x.de
(Internet) Connection available?
« on: July 30, 2014, 11:30:09 am »
Hi,

as you may know, I am working on Hase right now. To test whether a connection is available I try to resolve the game server of the hase. If this fails, I know: No connection. On the pandora this is quite fast (instant). But it seems to take a while on the GCW. Waiting 10 seconds or more until it fails, is not acceptable.

So what method is the easiest way to check for a working internet connection on the GCW? Here were a lot of suggestions:
http://stackoverflow.com/questions/929368/how-to-test-a-internet-connection-in-bash
Based on ping, wget, telnet and even some linux magic about /sys... But which method is the fastest? Any ideas? If possible, it would also help, if you could test some possibilities for me as I don't own a GCW. :\

Thanks for your help!

Greetings, Ziz
I am a leaf on the wind - watch how I soar. Wash

zear

  • * Moderator
  • Posts: 2381
Re: (Internet) Connection available?
« Reply #1 on: July 30, 2014, 03:56:21 pm »
The wi-fi chip is being powered off if not used, so if there is no wlan0 interface - you can assume there is no Internet connection.

Ziz (OP)

  • Posts: 285
    • http://ziz.gp2x.de
Re: (Internet) Connection available?
« Reply #2 on: July 30, 2014, 11:25:15 pm »
But what about network via usb or usb-ethernet dongle?
And just being in a wlan network, doesn't mean, that this network has internet access. :\
I am a leaf on the wind - watch how I soar. Wash

pcercuei

  • Posts: 1720
    • My devblog
Re: (Internet) Connection available?
« Reply #3 on: July 31, 2014, 12:32:49 am »
What I usually do is ping 8.8.8.8.
That's Google's DNS, you can be assured that it will never be down  ;D

Ziz (OP)

  • Posts: 285
    • http://ziz.gp2x.de
Re: (Internet) Connection available?
« Reply #4 on: July 31, 2014, 09:19:05 am »
Did you test this on the GCW? Is it fast? What about networks, that block ping messages? Does such a thing exist?
I am a leaf on the wind - watch how I soar. Wash

mth

  • Posts: 319
Re: (Internet) Connection available?
« Reply #5 on: August 04, 2014, 01:33:20 am »
In my opinion you shouldn't try any tricks to determine whether you have an internet connection: if you're not testing the exact thing you need, there will be situations in which your test provides the wrong result. Also you'd be making your code and its behavior more complex.

I think there are two components to a proper solution:
  • OpenDingux should fail fast if there is no chance at all of a successful DNS lookup
  • Hase should deal with DNS lookups that don't fail fast

About point 1: When I try command line stuff (nslookup, ssh) when the Zero is networked via USB, name resolution fails immediately. So I cannot reproduce the problem you're describing. Could you make a minimal test case that demonstrates the problem? What kind of networking is active on the Zero? Is there anything in "/etc/resolv.conf"?

About point 2: If you know you have a responsive server, you can reduce the timeout. Also you can contact the server asynchronously such that the user interface doesn't block while Hase is waiting for the server's reply.

Ziz (OP)

  • Posts: 285
    • http://ziz.gp2x.de
Re: (Internet) Connection available?
« Reply #6 on: August 04, 2014, 12:16:21 pm »
In my opinion you shouldn't try any tricks to determine whether you have an internet connection: if you're not testing the exact thing you need, there will be situations in which your test provides the wrong result. Also you'd be making your code and its behavior more complex.
That's in fact okay, if I encapsulate it well. ;)

Quote
I think there are two components to a proper solution:
  • OpenDingux should fail fast if there is no chance at all of a successful DNS lookup
  • Hase should deal with DNS lookups that don't fail fast

About point 1: When I try command line stuff (nslookup, ssh) when the Zero is networked via USB, name resolution fails immediately. So I cannot reproduce the problem you're describing. Could you make a minimal test case that demonstrates the problem? What kind of networking is active on the Zero? Is there anything in "/etc/resolv.conf"?
I have no idea. What I do is:
Getting the IP via DNS lookup via SDL_net.
If this IP is invalid, I know, the connection is missing. On the Pandora this is quite fast. Also on the PC. But somebody mentioned, that this may take a while on the GCW. This problem also exists for me C4A implementation afaik. I could make a simple shell program, which tries to lookup a DNS with the same method and return whether this connection is availbale or not. Does this help?

Quote
About point 2: If you know you have a responsive server, you can reduce the timeout. Also you can contact the server asynchronously such that the user interface doesn't block while Hase is waiting for the server's reply.
Yes I could make a thread for this. I will think about this sollution as it seems to be the best. However it is harder so synchronize and more special cases pop up like creating a game if an update is running right now. Do I wait for the update state? Do I use the old state? Do I assume being offline as long as the check runs?

Furthermore using a timeout means killing the SDL_Net function for DNS lookup. I don't know, whether this is a good idea...
I am a leaf on the wind - watch how I soar. Wash

mth

  • Posts: 319
Re: (Internet) Connection available?
« Reply #7 on: August 04, 2014, 12:48:57 pm »
In my opinion you shouldn't try any tricks to determine whether you have an internet connection: if you're not testing the exact thing you need, there will be situations in which your test provides the wrong result. Also you'd be making your code and its behavior more complex.
That's in fact okay, if I encapsulate it well. ;)
Encapsulating it well will help against code complexity, but not against getting the wrong result. For example, let's say you implement pinging 8.8.8.8, that will fail if a firewall or proxy blocks pings, it will fail on IPv6-only networks and it will fail if Google ever decides to either stop providing DNS services or turns off ping replies on their server.

When I try command line stuff (nslookup, ssh) when the Zero is networked via USB, name resolution fails immediately. So I cannot reproduce the problem you're describing. Could you make a minimal test case that demonstrates the problem? What kind of networking is active on the Zero? Is there anything in "/etc/resolv.conf"?
I have no idea. What I do is:
Getting the IP via DNS lookup via SDL_net.
If this IP is invalid, I know, the connection is missing. On the Pandora this is quite fast. Also on the PC. But somebody mentioned, that this may take a while on the GCW. This problem also exists for me C4A implementation afaik. I could make a simple shell program, which tries to lookup a DNS with the same method and return whether this connection is availbale or not. Does this help?
It helps if it demonstrates the problem. "Somebody mentioned" means that you didn't encounter the problem yourself?

If you know you have a responsive server, you can reduce the timeout. Also you can contact the server asynchronously such that the user interface doesn't block while Hase is waiting for the server's reply.
Yes I could make a thread for this. I will think about this sollution as it seems to be the best. However it is harder so synchronize and more special cases pop up like creating a game if an update is running right now. Do I wait for the update state? Do I use the old state? Do I assume being offline as long as the check runs?
You don't have to make the game behave very differently: just showing some animation to indicate something is happening and having a cancel button is already a big improvement over a frozen UI. For example, the user might realize networking is off and want to leave the game to go and turn on networking; in that case it is useful to be able to cancel after 1 second instead of having to wait for a 10 or 30 second time-out to happen.

Furthermore using a timeout means killing the SDL_Net function for DNS lookup. I don't know, whether this is a good idea...
Killing a thread is always a bad idea: it could leak resources or even leave locks in a locked state forever. The networking thread will return at some point, so you could leave the thread running and ignore its eventual returned value. To the rest of the program that has the same effect as killing the thread, but without the risks.

Ziz (OP)

  • Posts: 285
    • http://ziz.gp2x.de
Re: (Internet) Connection available?
« Reply #8 on: August 04, 2014, 03:28:04 pm »
It helps if it demonstrates the problem. "Somebody mentioned" means that you didn't encounter the problem yourself?
I don't own a GCW.

Quote from: mth
You don't have to make the game behave very differently: just showing some animation to indicate something is happening and having a cancel button is already a big improvement over a frozen UI. For example, the user might realize networking is off and want to leave the game to go and turn on networking; in that case it is useful to be able to cancel after 1 second instead of having to wait for a 10 or 30 second time-out to happen.
Good point. I will think about it.

Quote from: mth
Killing a thread is always a bad idea: it could leak resources or even leave locks in a locked state forever. The networking thread will return at some point, so you could leave the thread running and ignore its eventual returned value. To the rest of the program that has the same effect as killing the thread, but without the risks.
Hm, you are right. In fact I could just ignore the thread after pressing Cancel...
I am a leaf on the wind - watch how I soar. Wash

 

Post a new topic