예제 #1
0
        public void Send(int opCode, int subCode, object value)
        {
            SocketMsg msg = new SocketMsg(opCode, subCode, value);

            msg.OpCode  = opCode;
            msg.SubCode = subCode;
            msg.Value   = value;
            byte[] data   = EncodeTool.EncodeMsg(msg);
            byte[] packet = EncodeTool.EncodePacket(data);

            Send(packet);
        }
예제 #2
0
        //处理接收的数据
        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();
        }