Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by jeh_dias18 · Mar 09, 2016 at 03:46 PM · unity 5json

How to reduce the number of WWW requests?

 private GameObject[] Photos;
     private static int size = Gallery.getSizeImagesPerGallery();
     private WWW www2;
     private WWW www;
     private IEnumerable<String> recebe;
     // Use this for initialization
     void Start ()
     {
         string LinkJsonFile = "...";
         /*www = new WWW(LinkJsonFile);
         yield return www.text;
         if(www.isDone){
             string aux = www.text;
             Debug.Log("Baixou uma imagem -- 1");
 
             TreatmentString(aux);
             ClearWWW(www);
         }*/
 
         StartCoroutine (UpLoadImages(LinkJsonFile));
 
     }
 
     IEnumerator UpLoadImages (string url)
     {
         www = new WWW (url);
         yield return www;
         string aux = www.text;
         TreatmentString(aux);
         //Debug.Log("text" + www.text);
         Debug.Log("Baixou uma imagem -- 1");
         ClearWWW(www);
     }
 
     void TreatmentString (string urlJson)
     {
         string aux = urlJson.Replace ("\\", "");
         PopulateLinksAndTitles(aux);
     }
     public GameObject prefab;
 
     void PopulateLinksAndTitles (string content)
     {
         string aux = "";
         string aux2 = "";
         List<string> LinksImages = new List<string> ();
         List<string> TitlesImages = new List<string> ();
         JSONNode json = JSON.Parse (content);
         Photos = GameObject.FindGameObjectsWithTag("Photos"); 
         for (int i = 0; i < size; i++) {
             aux = json ["content"] ["videos"] [i] ["image_url"].Value;
             www2 = new WWW(aux);
             aux2 = json ["content"] ["videos"] [i] ["title"].Value;
 
             Photos = GameObject.FindGameObjectsWithTag("Photos");
 
             StartCoroutine (CarriesThumbs (aux, aux2, www2,Photos[i]));
         }
 
     }
 
     IEnumerator CarriesThumbs (string url, string TitleImage, WWW www2,GameObject Photo)
     {
 
             www2.threadPriority = ThreadPriority.High;
             yield return www2;
             Debug.Log("Baixou uma imagem -- 2");
             Photo.name = TitleImage;
             Photo.GetComponent<MeshRenderer>().material.name = url;
             MeshRenderer render = Photo.GetComponent<MeshRenderer> ();
             Texture2D texture = www2.texture;
             render.material.mainTexture = texture;
             if (www2 == null) {
                 Debug.LogError ("Failed to get the payload.");
             }
             if (www2.error != null) {
                 Debug.LogError ("Error occurred during download " + www2.error);
             }
 
             ClearWWW(www2);
     }
 
     public void ClearWWW (WWW www)
     {
         if (www != null) {
             www.Dispose();
             www = null;
             System.GC.Collect();
         }
     }

I step to the WWW a URL that contains a json file and this file contains 60 urls images.

But when I call the method updateImage I have 13 calls to www.

And after the call of the other methods, there are 430 requests. But I need a request to get the text from the remote json file and another 60 requests for each image.

How can I handle this problem?

Because the occurrence of escessivas requests I get the following errors:

Error occurred during download Recv failure: Connection was reset

You are trying to load data from a www stream which had the following error when downloading. Recv failure: Connection was reset

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

73 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

Related Questions

Unity for each JSONnode in JSONObject 0 Answers

How to prevent to save or send a big json string? 0 Answers

Loading JSON from StreamingAssets on android(c#) 0 Answers

JSON to Object error Object reference not set to an instance of an object 1 Answer

Reading json file 1 Answer


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