Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save slambert/23c44d0f2136766de3b8d277980abb20 to your computer and use it in GitHub Desktop.
Save slambert/23c44d0f2136766de3b8d277980abb20 to your computer and use it in GitHub Desktop.
This uses processing to see if you're currently connected to the internet.
/* Very expensive network connection checker
Steve Lambert 2017-04-26
*/
void setup() {
size(250,250);
smooth();
} // end setup
void draw() {
if (frameCount % 100 == 0){ // every 100th frame do this...
// pull lines of text from google's webpage into a string:
String[] lines = loadStrings("http://google.com");
// Now, check to see if anything comes back. If nothing comes
// back, it returns "null". If we don't check for that, it
// will cause an error and the program will crash. So we test
// for null, which will tell us if we're connected at all.
if (lines == null){
println("congratulations, you're off the internet");
} else {
//println("there are " + lines.length + " lines");
println("Hi, I see you're on the internet");
}
}
} // end draw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment