Quantcast
Channel: Questions in topic: "httpwebrequest"
Viewing all articles
Browse latest Browse all 190

Unity web request sometimes appear Error:System.Exception: Code:0 Error:Cannot resolve destination host

$
0
0
My problem is that I use unity web request for hotfix. 90% of the time, players can perform web reqeust normally. Sometimes you will encounter Error:System.Exception: Code:0 Error:Cannot resolve destination host error. I'm pretty sure that the player's network is fine, because when an error occurs, he sends the event back to my server. I'm also sure that the server of the download source is also fine, because I have passed the cdn of azure and google, and it is unlikely that these two big companies have problems together. Would like to ask if there are any developers who have encountered the same problem, or know how to solve this problem, thank you very much! public class UnityWebRequestDownloader : AbstractDownloader { private static readonly ILog log = LogManager.GetLogger(typeof(UnityWebRequestDownloader)); public UnityWebRequestDownloader(Uri baseUri) : this(baseUri, SystemInfo.processorCount * 2) { } public UnityWebRequestDownloader(Uri baseUri, int maxTaskCount) : base(baseUri, maxTaskCount) { } protected override IEnumerator DoDownloadBundles(IProgressPromise promise, List bundles) { long totalSize = 0; long downloadedSize = 0; Progress progress = new Progress(); List list = new List(); for (int i = 0; i < bundles.Count; i++) { var info = bundles[i]; totalSize += info.FileSize; if (BundleUtil.Exists(info)) { downloadedSize += info.FileSize; continue; } list.Add(info); } progress.TotalCount = bundles.Count; progress.CompletedCount = bundles.Count - list.Count; progress.TotalSize = totalSize; progress.CompletedSize = downloadedSize; yield return null; List> tasks = new List>(); for (int i = 0; i < list.Count; i++) { BundleInfo bundleInfo = list[i]; string fullname = BundleUtil.GetStorableDirectory() + bundleInfo.Filename; UnityWebRequest www = new UnityWebRequest(GetAbsoluteUri(bundleInfo.Filename)); www.downloadHandler = new DownloadFileHandler(fullname); #if UNITY_2018_1_OR_NEWER www.SendWebRequest(); #else www.Send(); #endif tasks.Add(new KeyValuePair(bundleInfo, www)); while (tasks.Count >= this.MaxTaskCount || (i == list.Count - 1 && tasks.Count > 0)) { long tmpSize = 0; for (int j = tasks.Count - 1; j >= 0; j--) { var task = tasks[j]; BundleInfo _bundleInfo = task.Key; UnityWebRequest _www = task.Value; if (!_www.isDone) { tmpSize += (long)Math.Max(0, _www.downloadedBytes);//the UnityWebRequest.downloadedProgress has a bug in android platform continue; } progress.CompletedCount += 1; tasks.RemoveAt(j); downloadedSize += _bundleInfo.FileSize; #if UNITY_2018_1_OR_NEWER if (_www.isNetworkError) #else if (_www.isError) #endif { promise.SetException(new Exception(_www.error)); if (log.IsErrorEnabled) log.ErrorFormat("Downloads AssetBundle '{0}' failure from the address '{1}'.Code:{2} Reason:{3}", _bundleInfo.FullName, GetAbsoluteUri(_bundleInfo.Filename), _www.responseCode, _www.error); _www.Dispose(); try { foreach (var kv in tasks) { kv.Value.Dispose(); } } catch (Exception) { } yield break; } _www.Dispose(); } progress.CompletedSize = downloadedSize + tmpSize; promise.UpdateProgress(progress); yield return null; } } promise.SetResult(true); } }

Viewing all articles
Browse latest Browse all 190

Trending Articles



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