Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by aabb15768 · Jun 02 at 08:24 PM · httpwebrequest

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

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<Progress, bool> promise, List<BundleInfo> bundles)
         {
             long totalSize = 0;
             long downloadedSize = 0;
             Progress progress = new Progress();
             List<BundleInfo> list = new List<BundleInfo>();
             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<KeyValuePair<BundleInfo, UnityWebRequest>> tasks = new List<KeyValuePair<BundleInfo, UnityWebRequest>>();
             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, UnityWebRequest>(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);
         }
     }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

137 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

No valid Cross Domain Policy with FTPWebRequest 1 Answer

IOS HTTP GET with Authorization Header not being sent 0 Answers

UnityWebRequest very slow 1 Answer

WWW does not show Location in header response (302/Redirect) 1 Answer

Why is my WebGl build throwing a CORS data error? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges