예제 #1
0
        public override async Task Prime(PrimeRequest request, IServerStreamWriter <PrimeResponse> responseStream, ServerCallContext context)
        {
            Console.WriteLine("The Server Recieved the request: ");
            Console.WriteLine(request.ToString());
            int result;
            int k = 2;
            int N = request.Number;

            while (N > 1)
            {
                if (N % k == 0)
                {
                    result = k;
                    await responseStream.WriteAsync(new PrimeResponse()
                    {
                        Result = result
                    });

                    N /= k;
                }
                else
                {
                    k += 1;
                }
            }
        }
예제 #2
0
        public async override Task ListPrimeNumbers(PrimeRequest request, IServerStreamWriter <PrimeResponse> responseStream, ServerCallContext context)
        {
            Console.WriteLine("The server received the request: ");
            Console.WriteLine(request.ToString());

            var n = request.Number.A;
            var k = 2;

            while (request.Number.A > 1)
            {
                if (n % k == 0)
                {
                    n = n / k;
                    await responseStream.WriteAsync(new PrimeResponse()
                    {
                        Result = k
                    });
                }
                else
                {
                    k = k + 1;
                }
            }
        }