Ejemplo n.º 1
0
        /// <summary>
        /// 处理接收数据,如果处理完成就直接回调函数给应用层
        /// </summary>
        private void processReceive()
        {
            isReceiveProcess = true;
            //处理数据
            byte [] data = EncodeTool.DecodePacket(ref dataCache);
            //Console.WriteLine("接收数据成功"+ data == null);
            if (data == null)
            {
                isReceiveProcess = false;
                return;
            }
            //TODO 需要再次转成一个具体的类型功我们使用
            SocketMsg value = EncodeTool.DecodeMsg(data);

            //Console.WriteLine((value.Value as string));
            if (value != null)
            {
                //这样子调用函数
                receiveCompeleted(this, value);
            }
            //
            //Console.WriteLine("接收数据成功");
            //回调上层,尾递归,继续处理,直到为空
            processReceive();
        }
Ejemplo n.º 2
0
        private void processRecive()
        {
            IsReciveProcess = true;
            //解析数据包
            byte[] data = EncodeTool.DecodePacket(ref dataCache);

            if (data == null)
            {
                IsReciveProcess = false;
                return;
            }

            SocketMessage msg = EncodeTool.DecodeMsg(data);

            //回调给上层
            reciveCompleted?.Invoke(this, msg);

            processRecive();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 处理接收的数据
        /// </summary>
        private void ProcessReceive()
        {
            isReceiveProcess = true;

            byte[] data = EncodeTool.DecodePacket(ref dataCacheList);  // 拆包
            if (data == null)
            {
                isReceiveProcess = false;
                return;
            }

            // 把 data 再次转成一个具体的数据类型 , 供我们使用
            SocketMsg msg = EncodeTool.DecodeMsg(data);

            // 回调给上层
            if (rc != null)
            {
                rc(this, msg);
            }
            // 尾递归
            ProcessReceive();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 处理接受的数据
        /// </summary>
        private void processReceive()
        {
            isReceiveProcess = true;
            //解析数据包
            byte[] data = EncodeTool.DecodePacket(ref dataCache);

            if (data == null)
            {
                isReceiveProcess = false;
                return;
            }

            SocketMsg msg = EncodeTool.DecodeMsg(data);

            //回调给上层
            if (receiveCompleted != null)
            {
                receiveCompleted(this, msg);
            }

            //尾递归
            processReceive();
        }