コード例 #1
0
ファイル: Network.cs プロジェクト: Lenovezhou/Screenshow
        public void Send(MsgBase msg)
        {
            if (msg == null)
            {
                return;
            }

            //int sendTime;
            //if (m_WaitForAnswer.TryGetValue(msg.GetMsgType(), out sendTime))
            //{
            //    if (sendTime != 0 && Environment.TickCount - sendTime < MaxRPCWaitTime)
            //    {
            //        return;
            //    }
            //}

            if (Environment.TickCount - m_LastResetTime > SendMsgCycle)
            {
                m_CurSendMsgNum = 0;
                m_LastResetTime = Environment.TickCount;
            }
            else
            {
                if (m_CurSendMsgNum >= MaxSendMsgNum)
                {
                    //m_Log.ErrorFormat("Too Much Message! Type: {0}", msg.GetMsgType());
                    return;
                }
            }

            if (m_CurSendMsgNum == 0)
            {
                m_LastResetTime = Environment.TickCount;
            }

            SendMsgPacket.Instance.Init(msg.GetMsgType());
            SendMsgPacket rPacket = SendMsgPacket.Instance;

            msg.Serialize(rPacket);
            SendData(rPacket.ToArray(), rPacket.GetLength());


            //if (m_WaitForAnswer.ContainsKey(msg.GetMsgType()))
            //{
            //    m_WaitForAnswer[msg.GetMsgType()] = Environment.TickCount;
            //}

            ++m_CurSendMsgNum;
        }