Ejemplo n.º 1
0
        private Task <Request> HandleRequest(TcSocketConnection client)
        {
            var inputStream  = new CodedInputStream(client.Connection.GetStream());
            var outputStream = new CodedOutputStream(client.Connection.GetStream());

            while (client.Connection.Connected)
            {
                Int32 varintLength = inputStream.ReadLength();

                Console.WriteLine("message length: {0}", varintLength);

                if (varintLength > 4)
                {
                    throw new System.ArgumentOutOfRangeException("varint");
                }

                try
                {
                    var request = Request.Parser.ParseFrom(inputStream.ReadBytes());
                    Console.WriteLine("message: {0} type {1}", request.CalculateSize(), request.ValueCase);
                    outputStream.WriteBytes(inputStream.ReadBytes());
                }
                catch (Exception ex)
                {
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        private Task <Request> HandleRequest(TcSocketConnection client)
        {
            var inputStream  = new CodedInputStream(client.Connection.GetStream());
            var outputStream = new CodedOutputStream(client.Connection.GetStream());

            //while(client.Connected)
            //{
            Int32 varintLength = inputStream.ReadLength();

            Console.WriteLine("message length: {0}", varintLength);

            if (varintLength > 4)
            {
                throw new System.ArgumentOutOfRangeException("varint");
            }

            try
            {
                var request = Request.Parser.ParseFrom(inputStream.ReadBytes());
                Console.WriteLine("message: {0} type {1}", request.CalculateSize(), request.ValueCase);
                outputStream.WriteBytes(inputStream.ReadBytes());
            }
            catch (Exception ex)
            {
            }



            //byte[] msgLengthField = new byte[varintLength];
            //stream.ReadAsync(msgLengthField, 1, varintLength);

            //Int64 msgLengthLong = BitConverter.ToInt64(msgLengthField, 0);

            //if (msgLengthLong > Int32.MaxValue)
            //{
            //    throw new System.ArgumentOutOfRangeException("messageLength");
            //}

            //Int32 messageLength = (Int32)msgLengthLong;
            //CodedInputStream.
            //Request request = Request.Parser.ParseFrom()
            //}



            //if(varintLength)
            return(null);
        }