Esempio n. 1
0
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="msg"></param>
        public override void SendMessage(PBBody pbbody)
        {
            PBPacket packet = PBUtils.NewPacket(pbbody);

            try {
                mSendQueue.Enqueue(packet);
            } catch (Exception ex) {
                new Exception(ex.ToString());
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 获取包体大小
        /// </summary>
        /// <param name="protoBuff"></param>
        /// <returns></returns>
        public static Int32 GetPBBodyLength(PBBody pbbody)
        {
            int length = 0;

            using (MemoryStream m = new MemoryStream()) {
                RuntimeTypeModel.Default.Serialize(m, pbbody);
                length = (Int32)m.Length;
            }
            return(length);
        }
Esempio n. 3
0
 /// <summary>
 /// 将包体转为流
 /// </summary>
 /// <param name="pbbody"></param>
 /// <returns></returns>
 public static byte[] PBBody2Buffer(PBBody pbbody)
 {
     byte[] buffer = null;
     using (MemoryStream m = new MemoryStream()) {
         RuntimeTypeModel.Default.Serialize(m, pbbody);
         m.Position = 0;
         int length = (int)m.Length;
         buffer = new byte[length];
         m.Read(buffer, 0, length);
     }
     return(buffer);
 }
Esempio n. 4
0
        /// <summary>
        /// 生成消息包
        /// </summary>
        /// <param name="pbbody"></param>
        /// <returns></returns>
        public static PBPacket NewPacket(PBBody pbbody)
        {
            PBPacket packet = new PBPacket();
            PBHead   header = new PBHead();

            header.mMessageId = GetPacketId(pbbody.GetType());
            header.mBodyLen   = GetPBBodyLength(pbbody);
            header.mTimeStamp = DateTime.Now.Ticks;

            packet.mHead = header;
            packet.mBody = pbbody;

            return(packet);
        }
Esempio n. 5
0
        /// <summary>
        /// 发送Http消息
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="key"></param>
        public override void SendMessage(PBBody msg, string key = null)
        {
            PBPacket packet = PBUtils.NewPacket(msg);

            if (string.IsNullOrEmpty(key))
            {
                return;
            }
            mReqUrl = mURL + key;
            try {
                mSendQueue.Enqueue(packet);
            } catch (Exception ex) {
                throw new Exception(ex.ToString());
            }
        }
 public void SendMessage(PBBody msg, string key = null)
 {
     if (mNetwork == null)
     {
         return;
     }
     if (mNetwork is HttpNetwork)
     {
         mNetwork.SendMessage(msg, key);
     }
     if (mNetwork is SocketNetwork)
     {
         mNetwork.SendMessage(msg);
     }
 }
Esempio n. 7
0
 /// <summary>
 /// 发送消息
 /// </summary>
 /// <param name="msg"></param>
 public virtual void SendMessage(PBBody msg)
 {
 }
Esempio n. 8
0
 /// <summary>
 /// 发送消息
 /// </summary>
 /// <param name="msg"></param>
 /// <param name="key"></param>
 public virtual void SendMessage(PBBody msg, string key)
 {
 }