Ejemplo n.º 1
0
        protected IEnumerator _ProcessConnectionQueue()
        {
            while (ConnectionQueue.Count > 0)
            {
                string data      = ConnectionQueue.Peek();
                string urlString = appHost + "/i?" + data;

                Log("Request started: " + urlString);

                WWW www = new WWW(urlString)
                {
                    threadPriority = ThreadPriority.Low
                };

                yield return(www);

                if (string.IsNullOrEmpty(www.error) == false)
                {
                    Log("Request failed: " + www.error);
                    break;
                }

                ConnectionQueue.Dequeue();
                Log("Request completed");
            }

            _isProcessingConnection = false;
        }
Ejemplo n.º 2
0
        protected IEnumerator _ProcessConnectionQueue(bool request)
        {
            Log("Start send requests");
            int retry = 0;

            while (ConnectionQueue.Count > 0)
            {
                string data = ConnectionQueue.Peek();
                string urlString;

                if (!request)
                {
                    urlString = appHost + "/i?" + data;
                }
                else
                {
                    urlString = appHost + "/" + data;
                }

                Log("Request started: <" + WWW.UnEscapeURL(urlString) + ">");

                WWW www = new WWW(urlString)
                {
                    threadPriority = ThreadPriority.Low
                };

                yield return(www);

                if (string.IsNullOrEmpty(www.error) == false && retry < maxRetries)
                {
                    Log("Request failed: " + www.error);
                    Log("Wait 5 seconds before try again");
                    yield return(new WaitForSeconds(5f)); //wait 5 seconds before try to send analytics again

                    retry++;
                }
                else
                {
                    ConnectionQueue.Dequeue();
                    if (retry >= maxRetries)
                    {
                        Log(string.Format("Request failed after {0} retries", retry));
                    }
                    else
                    {
                        Log("Request successful: <" + www.text + ">");
                    }
                    retry = 0;
                }

                if (ConnectionQueue.Count > 0)   //if we have more requests
                {
                    Log("Wait 0.2 sec before exit");
                    yield return(new WaitForSeconds(0.2f));    //don't allow to send more than 5 request per second
                }
            }

            _isProcessingConnection = false;
            Log("End send requests");
        }