コード例 #1
0
        // Send heart beat msg
        private void TimerSendHeartBeatMsg()
        {
            DateTime utcNow      = DateTime.UtcNow;
            TimeSpan elapsedTime = utcNow - m_send_heartbeat_time;

            // Send heart beat msg per 5 seconds
            if (elapsedTime.TotalSeconds >= 5)
            {
                CG_HeartBeat_Msg stHBMsg = new CG_HeartBeat_Msg();
                stHBMsg.heartbeat_index = m_heartbeat_index;
                SendMsgToServer(stHBMsg);
                ++m_heartbeat_index;
                m_send_heartbeat_time = utcNow;
            }
        }
コード例 #2
0
        // Verify msg type: CG_HeartBeat_Msg
        private static void Verify_CG_HeartBeat_Msg()
        {
            CG_HeartBeat_Msg stSrc = new CG_HeartBeat_Msg();

            // Make object rand
            stSrc.heartbeat_index = 125;
            byte[]           src_bytes = stSrc.ToBytes();
            MBinaryReader    mbr       = new MBinaryReader(src_bytes);
            CG_HeartBeat_Msg stDst     = new CG_HeartBeat_Msg();

            stDst.msg_len = mbr.ReadUInt16();
            stDst.msg_id  = mbr.ReadUInt16();
            stDst.FromBytes(mbr);
            // Verify object content
            if (stDst.msg_len != CG_HeartBeat_Msg.MSG_LEN)
            {
                Console.WriteLine("Failed to verify field: msg_len");
            }
            if (stDst.msg_id != CG_HeartBeat_Msg.MSG_ID)
            {
                Console.WriteLine("Failed to verify field: msg_id");
            }
            if (stSrc.heartbeat_index != stDst.heartbeat_index)
            {
                Console.WriteLine("Failed to verify field: heartbeat_index");
            }
            // Compare object by bytes
            byte[] dst_bytes = stDst.ToBytes();
            if (dst_bytes.Length != src_bytes.Length)
            {
                Console.WriteLine("Failed to verify field: CG_HeartBeat_Msg by bytes length");
            }
            for (int byte_index = 0; byte_index < dst_bytes.Length; ++byte_index)
            {
                if (src_bytes[byte_index] != dst_bytes[byte_index])
                {
                    Console.WriteLine("Failed to verify field: CG_HeartBeat_Msg by bytes length");
                }
            }
        }
コード例 #3
0
        public static Message CreateMessageById(AUINT16 nMsgId)
        {
            Message msg = null;

            switch (nMsgId)
            {
            case CG_HeartBeat_Msg.MSG_ID:
                msg = new CG_HeartBeat_Msg();
                break;

            case GC_HeartBeat_Msg.MSG_ID:
                msg = new GC_HeartBeat_Msg();
                break;

            case CG_Echo_Request.MSG_ID:
                msg = new CG_Echo_Request();
                break;

            case GC_Echo_Response.MSG_ID:
                msg = new GC_Echo_Response();
                break;

            case CG_Chat_Cmd.MSG_ID:
                msg = new CG_Chat_Cmd();
                break;

            case GC_Chat_Msg.MSG_ID:
                msg = new GC_Chat_Msg();
                break;

            default:
                Console.WriteLine("Invalid msg id:" + nMsgId);
                break;
            }
            return(msg);
        }