1 // Copyright 2015 gRPC authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 using System; 16 using Grpc.Core; 17 using Helloworld; 18 using CommandLine; 19 20 namespace GreeterClient 21 { 22 class Program 23 { 24 private class Options 25 { 26 [Option("server", Default = "localhost:50051", HelpText = "The address of the server")] 27 public string Server { get; set; } 28 } 29 Main(string[] args)30 public static void Main(string[] args) 31 { 32 Parser.Default.ParseArguments<Options>(args) 33 .WithParsed<Options>(options => RunClient(options)); 34 } 35 RunClient(Options options)36 private static void RunClient(Options options) 37 { 38 Channel channel = new Channel(options.Server, ChannelCredentials.Insecure); 39 40 var client = new Greeter.GreeterClient(channel); 41 String user = "you"; 42 43 var reply = client.SayHello(new HelloRequest { Name = user }); 44 Console.WriteLine("Greeter client received: " + reply.Message); 45 46 channel.ShutdownAsync().Wait(); 47 Console.WriteLine("Press any key to exit..."); 48 Console.ReadKey(); 49 } 50 } 51 } 52