Beispiel #1
0
        /// <summary>
        /// 处理接收的数据
        /// </summary>
        private void processPeceive()
        {
            isReciveProcess = true;

            //解析数据包
            byte[] data = EncodeTool.DecodePacket(ref dataCache);

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

            //TODO 需要再次转换成一个具体的类型 供我们使用
            SocketMsg msg = EncodeTool.DecodeMsg(data);

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

            //伪递归
            processPeceive();
        }
Beispiel #2
0
        /// <summary>
        /// 发送网络消息
        /// </summary>
        /// <param name="opCode">操作码</param>
        /// <param name="subCode">子操作</param>
        /// <param name="value">参数</param>
        public void Send(int opCode, int subCode, object value)
        {
            SocketMsg msg = new SocketMsg(opCode, subCode, value);

            byte[] data   = EncodeTool.EncodeMsg(msg);
            byte[] packet = EncodeTool.EncodePacket(data);

            Send(packet);
        }