示例#1
0
        public byte[] CryptoReceiveMsg()
        {
            bool        recvMode = false;
            BlindPacket packet   = new BlindPacket();

            byte[] result = null;
            do
            {
                packet = CryptoReceive(recvMode);
                if (packet.header == PacketType.Disconnect)
                {
                    return(null);
                }
                result = BlindNetUtil.MergeArray <byte>(result, packet.data);
                Debug.WriteLine("Receive {0}/{1} bytes", packet.data.Length, result.Length);
                recvMode = true;
            } while (packet.header == PacketType.Sending);
            result = BlindNetUtil.ByteTrimEndNull(result);
            return(result);
        }
示例#2
0
        public int CryptoSendPacket(byte[] data, PacketType header)
        {
            int         realSendBytes = 0;
            BlindPacket pack          = new BlindPacket();

            pack.header = header;
            pack.data   = new byte[BlindNetConst.DATASIZE];
            Array.Copy(data, 0, pack.data, 0, data.Length);
            byte[] encrypted = aes.Encryption(BlindNetUtil.StructToByte(pack));
            realSendBytes = socket.Send(encrypted, BlindNetConst.PACKSIZE, SocketFlags.None);
            new NetworkStream(socket).Flush();

            byte[] result = new byte[BlindNetConst.MINIPACKSIZE];
            int    rcvNum = socket.Receive(result, BlindNetConst.MINIPACKSIZE, SocketFlags.None);

            if (result[0] != (byte)PacketType.OK)
            {
                return(0);
            }
            return(realSendBytes);
        }