/// <summary>
        /// 封包
        /// </summary>
        /// <param name="msg">包体对象</param>
        /// <returns></returns>
        public byte[] Encode(TSocketMessage msg)
        {
            byte[] bytes;
            using (MemoryStream ms = new MemoryStream())
            {
                using (BinaryWriter bw = new BinaryWriter(ms, Encoding.UTF8))
                {
                    #region 封装包头
                    bw.Write((Int16)T1);
                    bw.Write((Int16)T2);
                    #endregion

                    #region 包协议
                    if (msg.MsgBuffer != null)
                    {
                        bw.Write((Int64)(4 + msg.MsgBuffer.Length));
                        bw.Write(msg.MsgId);
                        bw.Write(msg.MsgBuffer);
                    }
                    else
                    {
                        bw.Write((Int64)0);
                    }
                    #endregion

                    bytes = ms.ToArray();
                }
            }

            return(bytes);
        }
        /// <summary>
        /// 心跳包封包
        /// </summary>
        /// <returns></returns>
        public byte[] RncodeHeartbeat()
        {
            TSocketMessage msg = new TSocketMessage(0, System.Text.Encoding.UTF8.GetBytes("心跳"));

            return(Encode(msg));
        }