x


Best way to determine WWW timeout/404/etc.?

I need to load a random number of textures at runtime. They may or may not exist at the given URL, if the server is even up. Some of them might be local ("file:///...."). Eventually, I need to know when to give up looking for them.

Does the WWW object have a way of doing this? The .error member? Syntax?

more ▼

asked Jan 31 '11 at 04:16 AM

DaveA gravatar image

DaveA
26.5k 151 171 256

(comments are locked)
10|3000 characters needed characters left

2 answers: sort oldest

Yep, the .error property is exactly what you want

if (www.error != null)
{
    //you couldn't download for some reason. www.error will be the string saying why
}
more ▼

answered Jan 31 '11 at 04:31 AM

Mike 3 gravatar image

Mike 3
30.5k 10 65 253

So, to be sure, in the cases I worry about, isDone will never be true, but eventually error will be non-null? Or would isDone go true with the error too?

Jan 31 '11 at 04:45 AM DaveA

@DaveA: isDone will be true when it's done, regardless of errors.

Jan 31 '11 at 05:19 AM Eric5h5
(comments are locked)
10|3000 characters needed characters left

If I can follow up on this, it seems like the 404 error is actually not in the error attribute, but in the text attribute... I've had no problems with actually getting the WWW code to download my files and accessing my data, but when testing rainy day scenarios, such as file not existing, etc, the isDone property seems successfully set to true, but the error property is null... after spending some time stripping down my code to the simple use of WWW on its own, I found the actual 404 not found error string was in the text property. I noticed another post on here that someone had the same problem... is this a known issue with a potential resolution, otherwise what's a good simple way to detect this error, as the .NET XML parser seems to throw an exception when trying to parse this information. If anyone would like more information, I can post it...

Here is what I'm seeing in my Unity Web Log:

Success somehow...:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> 
    <html>
       <head> 
           <title>404 Not Found</title> 
       </head>
       <body> 
           <h1>Not Found</h1> 
           <p>The requested URL /sandboxes/applets/bootstrap/assetdownloads.xml was not found on this server.</p> 
       </body>
    </html>

from accessing WWW.text's property.

more ▼

answered Feb 23 '12 at 11:14 PM

cwodarcz gravatar image

cwodarcz
1 2 2

I'd hate to have to write a 'screen scraper' to detect 404's in text, because some servers are configured to put up cutsy stuff. I would think the headers should contain the 404 status, and those are available, if poorly documented.

Feb 29 '12 at 01:09 AM DaveA
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2204
x525
x54
x16
x4

asked: Jan 31 '11 at 04:16 AM

Seen: 2361 times

Last Updated: Feb 29 '12 at 01:09 AM