Quantcast
Viewing all articles
Browse latest Browse all 387

Using async WebRequest GetResponse

*Disclaimer*: This is a **friggin' really complicated question**. Probably what I wasted the most time out of anything I've ever done with Unity 3D in the past 5 years or so. And I'm still stuck here... So, be aware about all links before trying to answer! (although this will be most likely unanswered for evah!) I need 2 things: 1. check for internet connectivity. 2. compare file bundle versions to see if differs from local and web. [`WebRequest`][1] could solve both. I could get headers on any URL, thus verifying not only internet connectivity, but also if the server is up, without relying on [unreliable ping][2]. Also I could get the file length, without [needing to download it all first][3] with [`WWW`][4], and that would be good enough to check if the file is different. First problem is that method [`GetResponse` isn't asynchronous][5] like [`WWW`][6] and so it locks up the whole application while it is checking. When doing for several, hundreds, of files, it sums up a lot. Second problem is that [`BeginGetResponse` is so complicated][7] to implement that I found it impossible until now. I've built [many versions of a fine script][8], I called it [`WebAsync`][9], but now I just can't get around the issues on why `WebResponse` is failing. I do know it can be [way more complex than I would expect][10], but even then, it still gives me random results when I test, still bringing `null` when it shouldn't. Just today I decided to drop `WebAsync` in favor of `WWW`, and it was working much better already... But then I stumbled upon the already mentioned problem with getting file length and now I think it won't work because of *need #2*. Unless I drop the idea of using the file length and use a separated bundle version control file, kinda like unity do with external version control, and create a "meta" for each bundle. So, there are actually 2 kind of right answers (as usual) here. For the title, or for these needs (if there is another option). But, please, don't tell me I'll have to go forward with the last idea and keep meta files everywhere! I hate that idea... [1]: http://msdn.microsoft.com/en-us/library/86wf6409(v=vs.71).aspx [2]: http://answers.unity3d.com/questions/41408/is-it-possible-to-check-internet-conneciton-for-ww.html#answer-41411 [3]: http://answers.unity3d.com/questions/196661/extra-www-download-statistics.html [4]: http://docs.unity3d.com/Documentation/ScriptReference/WWW.html [5]: http://answers.unity3d.com/questions/41408/is-it-possible-to-check-internet-conneciton-for-ww.html#answer-343863 [6]: http://gamedev.stackexchange.com/questions/43749/the-underlying-mechanism-in-yield-return-www-of-unity3d-game-engine [7]: http://msdn.microsoft.com/en-us/library/system.net.webrequest.endgetresponse.aspx [8]: http://stackoverflow.com/a/12606963/274502 [9]: http://wiki.unity3d.com/index.php/WebAsync [10]: http://fearthecowboy.com/2011/09/02/fixing-webrequests-desire-to-throw-exceptions-instead-of-returning-status/

Viewing all articles
Browse latest Browse all 387

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>