示例#1
0
        /// <summary>
        /// 发送网络消息
        /// </summary>
        /// <param name="msg"></param>
        public void Send(SocketMsg msg)
        {
            byte[] data   = EncodeHelper.EncodeMsg(msg);
            byte[] packet = EncodeHelper.EncodePacket(data);

            sendQueue.Enqueue(packet);
            if (!isSendProcess)
            {
                ProcessSend();
            }
        }
示例#2
0
        /// <summary>
        /// 处理接收的数据
        /// </summary>
        private void ProcessReceive()
        {
            isProcess = true;
            //解析数据包
            byte[] data = EncodeHelper.DecodePacket(ref dataCache);
            if (data == null)
            {
                isProcess = false;
                return;
            }
            SocketMsg msg = EncodeHelper.DecodeMsg(data);

            //回调给上层
            receiveCompleted?.Invoke(this, msg);
            //伪递归
            ProcessReceive();
        }
示例#3
0
 /// <summary>
 /// 发送网络消息
 /// </summary>
 /// <param name="msg"></param>
 public void Send(SocketMsg msg)
 {
     byte[] data   = EncodeHelper.EncodeMsg(msg);
     byte[] packet = EncodeHelper.EncodePacket(data);
     Send(packet);
 }