static async Task Main(string[] args) { Channel channel = new Channel(target, ChannelCredentials.Insecure); await channel.ConnectAsync().ContinueWith((task) => { if (task.Status == TaskStatus.RanToCompletion) { Console.WriteLine("The client connected successfully"); } }); var client = new PrimeNumberService.PrimeNumberServiceClient(channel); var request = new PrimeNumberDecompositionRequest() { Number = 120 }; var response = client.PrimeNumberDecomposition(request); while (await response.ResponseStream.MoveNext()) { Console.WriteLine(response.ResponseStream.Current.PrimeFactor); await Task.Delay(200); } channel.ShutdownAsync().Wait(); Console.ReadKey(); }
//Server Streaming Prime public static async Task CalculatePrime(Channel channel) { var client = new PrimeNumberService.PrimeNumberServiceClient(channel); var request = new PrimeNumberDecompositionRequest() { Number = 120 }; var response = client.PrimeNumberDecomposition(request); while (await response.ResponseStream.MoveNext()) { Console.WriteLine(response.ResponseStream.Current.PrimeFactor); //One by one görmek için await Task.Delay(200); } }
public override async Task PrimeNumberDecomposition(PrimeNumberDecompositionRequest request, IServerStreamWriter <PrimeNumberDecompositionResponse> responseStream, ServerCallContext context) { Console.WriteLine("The server received the request :"); Console.WriteLine(request.ToString()); int number = request.Number; int divisor = 2; while (number > 1) { if (number % divisor == 0) { number /= divisor; await responseStream.WriteAsync(new PrimeNumberDecompositionResponse() { PrimeFactor = divisor }); } else { divisor++; } } }