예제 #1
0
        public static void Main(string[] args)
        {
            // Create a channel
            var channel = new Channel(Host + ":" + Port, ChannelCredentials.Insecure);

            // Create a client with the channel
            var client = new GreetingService.GreetingServiceClient(channel);

            // Create a request
            var request = new HelloRequest {
                Name      = "Mete - on C#",
                Age       = 34,
                Sentiment = Sentiment.Happy
            };

            // Send the request
            Console.WriteLine("GreeterClient sending request");
            var response = client.greeting(request);

            Console.WriteLine("GreeterClient received response: " + response.Greeting);

            // Shutdown
            channel.ShutdownAsync().Wait();
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
예제 #2
0
        public static void Main(string[] args)
        {
            // Create a channel
            var channel = new Channel(Host + ":" + Port, ChannelCredentials.Insecure);

            // Create a client with the channel
            var client = new GreetingService.GreetingServiceClient(channel);

            // Create a request
            var request = new HelloRequest
            {
                Name      = "Mete - on C#",
                Age       = 34,
                Sentiment = Sentiment.Happy
            };

            var pingTasks = new Task[1000];
            var stopwatch = Stopwatch.StartNew();

            for (var i = 0; i < pingTasks.Length; i++)
            {
                pingTasks[i] = Task.Factory.StartNew(() =>
                {
                    var response = client.greeting(request);
                    //Console.WriteLine("GreeterClient received response: " + response.Greeting);
                });
            }
            Task.WaitAll(pingTasks);
            stopwatch.Stop();

            Console.WriteLine($"Ping for {pingTasks.Length} tasks took: {stopwatch.ElapsedMilliseconds}ms");

            // Shutdown
            channel.ShutdownAsync().Wait();
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }