Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            var server = new Server
            {
                Services = { GreetService.BindService(new GreeterImpl()) },
                Ports    = { new ServerPort("localhost", Port, ServerCredentials.Insecure) }
            };

            server.Start();

            Console.WriteLine($"Greeter server listening on port {Port}");
            Console.WriteLine("Press any key to stop the server...");
            Console.ReadKey();

            server.ShutdownAsync().Wait();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Server server = null;

            try
            {
                string serverCertificate = File.ReadAllText("GRPCServer/ssl/server.crt");
                string serverKey         = File.ReadAllText("GRPCServer/ssl/server.key");
                string caCertificate     = File.ReadAllText("GRPCServer/ssl/ca.crt");
                SslServerCredentials serverCredentials = new SslServerCredentials(new List <KeyCertificatePair>()
                {
                    new KeyCertificatePair(serverCertificate, serverKey)
                }, caCertificate, true);

                server = new Server()
                {
                    Services = { GreetService.BindService(new GreetServiceConstruct()),
                                 SquareRootService.BindService(new SquareRootServiceConstruct()),
                                 BlogService.BindService(new BlogServiceConstruct()) },
                    Ports = { new ServerPort("localhost", _port, serverCredentials) }
                };

                server.Start();
                Console.WriteLine("The sever is listening on port: " + _port);
                Console.ReadKey();
            }
            catch (IOException e)
            {
                Console.WriteLine("The _server is failed to start " + e.Message);
            }
            finally
            {
                if (server != null)
                {
                    server.ShutdownAsync().Wait();
                }
            }
        }