Www class - no error when internet not present?

Hi all,

I’m trying to do a catch all “no internet present” in the event I get an error from the www class. The problem seems to be I don’t seem to get any error for any condition (no network present, network present no response from site, etc…). Does anyone know exactly what conditions should cause a error return on a www call? And how would one go about understanding what error conditions are possible to check for?

To take a side track, is there a real good way (in Unity) to detect the presents of a network connection?

Thanks,

Galen

Ok, I think I’ve found my answer… there isn’t a good one. Do a timeout inside Unity at the point you’re trying to call, or code a objective-c solution (more of a global effect as opposed to a test each time you need it kind of thing - at least in the example I found).

Oh well, time to choose… but first … off to the wish list forum :wink:

Thanks,

Galen

I would check the internet with a time out like you are doing but I would open a different thread and switch between the 2 while scores are loading.
I did this while I load high scores from the web for my global high scores

this is at the core of the high scores
there is a little more to do but this should help

it is in c# but java script is not that different ether way i recommend reading up on threads.

//-----------------------------------------------------------------//
// Function: globalScore(string initials, int score,int typeOfGame)
/// @brief sends new scores in and outputs your position in high scores
/// your highest score and the 10 highest scores
///
//-----------------------------------------------------------------//
public static string[ ] globalScore(string initials, int score,int typeOfGame){
GameType= typeOfGame;
ID=iPhoneSettings.uniqueIdentifier;
print(ID+“this is the ID”);
setOrGetScores=baseURL+“”+ “sendScore,getScores&deviceId=”+“” +ID+“&score=”+score+“&initials=”+initials+“&type=”+typeOfGame;
// there was a big non related comment here
t = new Thread(new ThreadStart(ThreadProc));
t.Start();
Thread.Sleep(2);
return lines;
}

//-----------------------------------------------------------------//
// Function: ThreadProc()
/// @brief this opens a new thread for loading the high scores
//-----------------------------------------------------------------//
public static void ThreadProc() {

print(ID+“this is the ID”);

string whereToGo= setOrGetScores;
WWW www = new WWW(whereToGo);
print(whereToGo) ;

float times= Time.realtimeSinceStartup;
float deltaTimes=0;

while ((!www.isDone(deltaTimes-times)<4)){
isSleeping=true;
//print(isSleeping);
Thread.Sleep(4);
deltaTimes= Time.realtimeSinceStartup;

}
//print(“happy Day”);

if (www.isDone){
stuffReturned =“\n”+ www.data;
scoreGottenOnce=true;

}
else{
stuffReturned = “error conecting to web”;
}
// turnes my string to an array
toArray();
//print(isSleeping);

isSleeping=false;
//print(“happy Day”);
t.Join();

}

That’s probably the best plan. Currently I’m using javascript for this piece, and as far as I can tell coroutines seem to either spawn a thread on call, or spawn a child process or fork it entirely… in any case, calling a coroutine does not stop the processing of the calling code unless you explicitly stop it (either by using a yield method call or some other technique).

The way I’m setup now, calling out to the internet doesn’t stop the Global scores page from rendering. However, my “no internet” message doesn’t show up until the magic moment that www decides to quite trying (roughly 1.5-2 mins!!!).

Now, where the failed call has no visible effect, I don’t put a window. Where the popup is necessary to explain why they don’t get those (sweet sweet) bragging rights :wink: I stop processing (not using yield… that thing kind of scares me… next thing I’ll be looking for my GOTO command… make the bad thoughts stop… must reboot… sys64738

Ahh that’s better :twisted:

Thanks for the example code though, I haven’t tried my hand at spawning threads in Unity/C# yet! I’m still trying to stop fighting my OO instincts (yes, for those Unity folks reading, I WOULD like to call constructors… a LOT! :slight_smile: :!:

Thanks again,

Galen

WWW class handling of exceptional cases will be improved with Unity iPhone 1.1. Additionally connectivity availability will be exposed to scripting as custom properties.

That’s fantastic!!!

I near lost my mind the other night staring at a www.error wishing (see the wish forum :wink: ) that I could simply do a quick check to see if the internet is available…

Now I’m reallllyy waiting for the 1.1!!

Thanks for the update,

Galen

Search the forum for “Reachability” and you’ll find some obj-c code to do this.

I’ll give that a try thanks! I did found some, I think posted by you, but it looked like it was something you call as the app starts, then you can read the results through playerprefs, but I didn’t see any examples where I could call out during runtime and check, or did I miss something?

I’d really like a “as needed” kind of solution, so If I’m playing the game several times, and my connectivity changes, I can submit a global high score or display the global high scores without having to restart to re-check in the middle. It looked from my previous searches the only “similar” work-around was to timeout the www request as a kind of catch all (no internet, website slow, site down, etc…) approach.

Thanks,

Galen