private void PublishStackedData()
    {
        if (!stackedCommands.Any())
        {
            return;
        }

        foreach (var command in stackedCommands)
        {
            webuSocket.Send(command.ToData());
        }
        stackedCommands.Clear();
    }
Exemple #2
0
        /// =============================================================================================
        /// <summary>
        /// データ送受信用ループ
        /// </summary>
        public void FixedUpdate()
        {
            ConnectStatusHandler();

            if (ConnectStatus != eConnectStatus.Connected)
            {
                return;
            }

            // Queueに貯まった送信データを送信
            if (sendQueue.Count > 0)
            {
                lock (sendLock)
                {
                    try
                    {
                        foreach (var data in sendQueue)
                        {
                            WebuSocket.Send(data);
                        }
                        sendQueue.Clear();
                    }
                    catch (Exception e)
                    {
                        Debug.LogError(e.ToString());
                    }
                }
            }

            // サーバから送信されてきたデータを取得
            if (0 < binaryQueue.Count)
            {
                lock (lockObj)
                {
                    try
                    {
                        foreach (var data in binaryQueue)
                        {
                            Receive(data);
                        }
                        binaryQueue.Clear();
                    }
                    catch (Exception e)
                    {
                        Debug.LogError(e.ToString());
                    }
                }
            }

            // RTTチェック(数値に変化があった時だけAction着火)
            timeCount -= Time.deltaTime;
            if (timeCount < 0f)
            {
                WebuSocket.Ping((rtt) => { Rtt = rtt; });
                timeCount = 1f;
            }
            if (_rtt != Rtt)
            {
                rttAct?.Invoke(Rtt);
                _rtt = Rtt;
            }
        }