Unity3D and C# - Having trouble getting endless data from the cloud

Hello,

I’m having some issues getting data from particle cloud.To read the data from particle cloud I use WWW class. But there is one problem - the stream of data from particle cloud is infinite, you can see it always updates when the link is opened in the browser and the WWW class returns the data only when it is downloaded. As the stream is endless this data acquisition can’t be done. What could be the solution for this?

For instance, I do not have problems gathering data in this form:
www.ourtechart.com//wp-content/uploads/2016/04/jsonAllData.txt2

In this case working code right now looks like this:

using UnityEngine;
using System.Collections;
public class particle : MonoBehaviour {

    string Url = "www.ourtechart.com//wp-content/uploads/2016/04/jsonAllData.txt";

IEnumerator Start()
{
    WWW www = new WWW(Url); // Start a download of the given URL (string defined elsewhere)
    yield return www; // Wait for download to complete

    // http://docs.unity3d.com/ScriptReference/WWW-text.html
    if (www.error == null)  {
        Debug.Log("Service data www: " + www);
        Debug.Log("Service data www.isDone: " + www.isDone);
        Debug.Log("Service data www.progress: " + www.progress);
        Debug.Log("Service data www.text: " + www.text);
        Debug.Log("Service data www.bytesDownloaded: " + www.bytesDownloaded );
        Debug.Log("Service data www.size: " + www.size );

        if (www.isDone && www.error == null) {
            Debug.Log("WE'VE GOT DATA!");
        }
    }
    else {
        Debug.Log("Error: " + www.error);
    }
}
}


As you can see with this example I can acquire data, what’s left - parse the data, which is not the issue.
The script should have the name “particle.cs” and attached to an empty gameObject in Unity3D.

If the String Url will be changed to the particle cloud link with access token we would not get any data as download never ends because of this: “yield return www; // Wait for download to complete”

Anyone has some ideas how to solve this?

Maybe you can use the UnityWebRequest class. There you can specify an own DownloadHandler (where you could handle the download yourself). But the class is experimental in Unity 5.3. In 5.4 no more.
I did get a unity crash using it in 5.3. But only in the scenario I posted in the thead.

Maybe this helps.

1 Like

Thanks! I’ll take a look.

By researching UnityWebRequest class I founded what I needed here. Thanks man.

Nice :wink:
I do just wonder if it’s a good idea to use System.Net.HttpWebRequest class. I used the UnityEngine.Networking.(Experimental).UnityWebRequest since I do want it to be supported on all platforms - I wonder if this is the case with the .net class direct also.

I have just tested out on Android smartphone - worked great! I Hope iOS devices would handle this without a problem too.

If that’s also working, I wonder why Unity makes it’s own class…