示例#1
0
        /// <summary>
        /// 发送网络消息
        /// </summary>
        /// <param name="opCode">操作码</param>
        /// <param name="subCode">子操作</param>
        /// <param name="value">参数</param>
        public void StartSend(int opCode, int subCode, object value)
        {
            MessageData msg = new MessageData(opCode, subCode, value);

            byte[] msgBytes  = EncodeTool.EncodeMsg(msg);
            byte[] msgPacket = EncodeTool.EncodeMessage(msgBytes);

            ////存到消息队列中
            //sendQueue.Enqueue(msgPacket);
            //if (!isSendProcess)
            //{
            //    Send();
            //}
            StartSend(msgPacket);
        }
示例#2
0
        /// <summary>
        /// 处理接收到的数据包
        /// </summary>
        private void ProcessReceive()
        {
            isReceiveProcess = true;

            //处理数据
            byte[] msgBytes = EncodeTool.DecodeMessage(ref data);

            if (msgBytes == null)  //数据包没有解析成功
            {
                isReceiveProcess = false;
                return;
            }


            MessageData msg = EncodeTool.DecodeMsg(msgBytes);

            //回调给上层
            receiveCompleted?.Invoke(this, msg);
            //递归
            ProcessReceive();
        }