- Home /
Is it possible to check internet conneciton for WWW class downloading ?
Hi,
I'm trying to download something through WWW class.When I'm connected to internet, there is no problem. But when I'm not connected , In editor, it returns WWW.error , but in standalone it remains at (yield www).
Is there any way to check internet connection ?
I'm using unity pro 2.6.1.
Hi
Hey, I found myself reading your question you said you could download things with the class WWW, look I tell you I'm doing an application in which I have to download files from a page x, but not e able to find me something to help me.
$$anonymous$$y question is if you pudes spend part of your code that makes the file download please only that part I'd appreciate it very much.
Answer by Justin Warner · Jan 05, 2011 at 02:37 PM
http://unity3d.com/support/documentation/ScriptReference/Ping.html
You could use this, and if isDone returns false, it's not connected, so then you can display a message.
Might work, not to sure, something to check out none-the-less.
This should not work for every case, because the HTTP server can block IC$$anonymous$$P (ping) requests.
Answer by Wajdi-azar · Jan 22, 2013 at 07:44 AM
WWW www; void Start() { www = new WWW("www.google.com"); StartCoroutine(checkConniction()); }
 IEnumerator  checkConniction()
 {
     yield return www;
     
     if(www.error != null)
     {
         print("faild to connect to internet, trying after 2 seconds.");
       yield return new WaitForSeconds(2);// trying again after 2 sec
       StartCoroutine(checkConniction());
     }else
     {
         print("connected to internet");
         // do somthing, play sound effect for example
         yield return new WaitForSeconds(5);// recheck if the internet still exists after 5 sec
          StartCoroutine(checkConniction());
         
     }
 
 }
Cheeers
Please help, it's not working on my android device
Answer by cregox · Nov 06, 2012 at 03:53 PM
Since I only want to check internet connection to reach some server, I use this:
     static public bool IsConnectionToServerOk () {
         WebRequest request = HttpWebRequest.Create(HomeGlobal.bundleURL);
         request.Method = "HEAD";
         WebResponse resp = null;
         try {
             resp = request.GetResponse();
         } catch {
             resp = null;
         }
         return resp != null;
     }
But this is too simplistic and very problematic if you can't afford to keep your whole application on hold for the response. **Using async calls as in here**, is much better.
Your answer
 
 
             Follow this Question
Related Questions
Get information from internet for my game 0 Answers
WWW/ yield calls throwing errors on iPad 1 Answer
Downloading files in the Editor 2 Answers
Google Insights 0 Answers
downloading file, saving on android 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                