Exemple #1
0
        // Send each queued json packet to the recipient which registered
        // with our dispatcher.
        void Dispatch()
        {
            lock (_locker)
            {
                List <string> msgs = ExtractJsonFromStream();
                foreach (string msg in msgs)
                {
                    try
                    {
                        //Only extract and propagate the last one to avoid to overload simulator in case of burst
                        JSONObject j = new JSONObject(msg);

                        string msg_type = j["msg_type"].str;

                        Debug.Log("Got: " + msg_type);

                        dispatcher.Dipatch(msg_type, j);
                    }
                    catch (Exception e)
                    {
                        Debug.LogError(e.ToString());
                    }
                }
            }
        }
        // Send each queued json packet to the recipient which registered
        // with our dispatcher.
        void Dispatch()
        {
            lock (_locker)
            {
                foreach (string str in recv_packets)
                {
                    // We have not had problems yet with message separation, but
                    // it could be added. Here we errors in case it becomes an issue.
                    try
                    {
                        JSONObject j = new JSONObject(str);

                        string msg_type = j["msg_type"].str;

                        Debug.Log("Got: " + msg_type);

                        dispatcher.Dipatch(msg_type, j);
                    }
                    catch (Exception e)
                    {
                        Debug.LogError(e.ToString());
                    }
                }

                recv_packets.Clear();
            }
        }