コード例 #1
0
    public IEnumerator Sender_AddQuest_Destroy_AddQuest()
    {
        int      count  = 0;
        FPClient client = new FPClient("52.83.245.22", 13325, 20 * 1000);

        client.Connect();
        yield return(new WaitForSeconds(1.0f));

        FPData data = new FPData();

        data.SetFlag(0x1);
        data.SetMtype(0x1);
        data.SetMethod("which");
        this._sender.AddQuest(client, data, this._payload, (cbd) => {
            count++;
        }, 5 * 1000);
        this._sender.Destroy();
        this._sender.AddQuest(client, this._data, this._payload, (cbd) => {
            count++;
        }, 5 * 1000);
        yield return(new WaitForSeconds(1.0f));

        this._sender.Destroy();
        client.Close();
        yield return(new WaitForSeconds(1.0f));

        Assert.AreEqual(1, count);
    }
コード例 #2
0
        private void SendEvents(List <object> items)
        {
            long salt = this.GenSalt();

            IDictionary <string, object> payload = new Dictionary <string, object>();

            payload.Add("pid", this._pid);
            payload.Add("sign", this.GenSign(salt));
            payload.Add("salt", salt);
            payload.Add("events", items);

            MemoryStream outputStream = new MemoryStream();

            MsgPack.Serialize(payload, outputStream);
            outputStream.Position = 0;

            byte[] bytes = outputStream.ToArray();

            FPData data = new FPData();

            data.SetFlag(0x1);
            data.SetMtype(0x1);
            data.SetMethod("adds");
            data.SetPayload(bytes);

            RUMClient self = this;

            this.SendQuest(data, (cbd) => {
                self._rumEvent.RemoveFromCache(items);

                Exception ex = cbd.GetException();

                if (ex != null)
                {
                    self.GetEvent().FireEvent(new EventData("error", ex));
                    self._rumEvent.WriteEvents(items);
                    return;
                }
            }, RUMConfig.SENT_TIMEOUT);
        }
コード例 #3
0
        private void LoadConfig()
        {
            if (this._debug)
            {
                Debug.Log("[RUM] load config...");
            }

            long salt = this.GenSalt();

            IDictionary <string, object> payload = new Dictionary <string, object>();

            payload.Add("pid", this._pid);
            payload.Add("sign", this.GenSign(salt));
            payload.Add("salt", salt);
            payload.Add("uid", this._uid);
            payload.Add("rid", this._rumEvent.GetRumId());

            payload.Add("lang", RUMPlatform.Instance.GetLang());
            payload.Add("manu", RUMPlatform.Instance.GetManu());
            payload.Add("model", RUMPlatform.Instance.GetModel());
            payload.Add("os", RUMPlatform.Instance.GetOS());
            payload.Add("osv", RUMPlatform.Instance.GetOSV());
            payload.Add("nw", RUMPlatform.Instance.GetNetwork());
            payload.Add("carrier", RUMPlatform.Instance.GetCarrier());
            payload.Add("from", RUMPlatform.Instance.GetFrom());
            payload.Add("appv", this._appv);

            MemoryStream outputStream = new MemoryStream();

            MsgPack.Serialize(payload, outputStream);
            outputStream.Position = 0;

            byte[] bytes = outputStream.ToArray();

            FPData data = new FPData();

            data.SetFlag(0x1);
            data.SetMtype(0x1);
            data.SetMethod("getconfig");
            data.SetPayload(bytes);

            RUMClient self = this;

            this.SendQuest(data, (cbd) => {
                Exception ex = cbd.GetException();

                if (ex != null)
                {
                    self._configVersion = 0;
                    self.GetEvent().FireEvent(new EventData("error", ex));
                    return;
                }

                IDictionary <string, object> dict = (IDictionary <string, object>)cbd.GetPayload();

                if (self._debug)
                {
                    Debug.Log("[RUM] load config: " + Json.SerializeToString(dict));
                }

                self._rumEvent.UpdateConfig((IDictionary <string, object>)dict["events"]);
            }, RUMConfig.SENT_TIMEOUT);
        }
コード例 #4
0
        private void SendPing(long timestamp)
        {
            if (this._lastPingTime == 0)
            {
                return;
            }

            if (timestamp - this._lastPingTime < RUMConfig.PING_INTERVAL)
            {
                return;
            }

            this._lastPingTime += RUMConfig.PING_INTERVAL;

            if (this._debug)
            {
                Debug.Log("[RUM] ping...");
            }

            long lastEid   = this._pingEid;
            int  lastCount = this._writeCount;

            this._writeCount = 0;
            this._pingEid    = MidGenerator.Gen();

            long salt = this.GenSalt();

            IDictionary <string, object> payload = new Dictionary <string, object>();

            payload.Add("pid", this._pid);
            payload.Add("sign", this.GenSign(salt));
            payload.Add("salt", salt);
            payload.Add("uid", this._uid);
            payload.Add("rid", this._rumEvent.GetRumId());
            payload.Add("sid", this._session);
            payload.Add("cv", this._configVersion);
            payload.Add("pt", this._pingLatency);
            payload.Add("ss", this._rumEvent.GetStorageSize());
            payload.Add("wc", lastCount);
            payload.Add("feid", lastEid);
            payload.Add("teid", this._pingEid);

            MemoryStream outputStream = new MemoryStream();

            MsgPack.Serialize(payload, outputStream);
            outputStream.Position = 0;

            byte[] bytes = outputStream.ToArray();

            FPData data = new FPData();

            data.SetFlag(0x1);
            data.SetMtype(0x1);
            data.SetMethod("ping");
            data.SetPayload(bytes);

            long      pingTime = timestamp;
            RUMClient self     = this;

            this.SendQuest(data, (cbd) => {
                self._pingLatency = Convert.ToInt32(ThreadPool.Instance.GetMilliTimestamp() - pingTime);

                Exception ex = cbd.GetException();

                if (ex != null)
                {
                    self.GetEvent().FireEvent(new EventData("error", ex));
                    return;
                }

                IDictionary <string, object> dict = (IDictionary <string, object>)cbd.GetPayload();

                if (self._debug)
                {
                    Debug.Log("[RUM] ping: " + Json.SerializeToString(dict));
                }

                self._rumEvent.SetTimestamp(Convert.ToInt64(dict["ts"]));
                self._rumEvent.SetSizeLimit(Convert.ToInt32(dict["bw"]));

                int cv = Convert.ToInt32(dict["cv"]);

                if (self._configVersion != cv || (cv == 0 && !self._rumEvent.HasConfig()))
                {
                    self._configVersion = cv;
                    this.LoadConfig();
                }
            }, RUMConfig.PING_INTERVAL);
        }