Пример #1
0
        static void Main(string[] args)
        {
            Server server = null;

            try
            {
                server = new Server()
                {
                    Services = { SqrtService.BindService(new SqrtServiceImpl()) },
                    Ports    = { new ServerPort("localhost", Port, ServerCredentials.Insecure) }
                };

                server.Start();
                Console.WriteLine("The server is listening on the port: " + Port);
                Console.ReadKey();
            }
            catch (IOException e)
            {
                Console.WriteLine("The server failed to start: " + e.Message);
                throw;
            }
            finally
            {
                if (server != null)
                {
                    server.ShutdownAsync().Wait();
                }
            }
        }
        static async Task Main(string[] args)
        {
            Server server = null;

            try
            {
                // reflection-1
                var reflectionServiceImpl = new ReflectionServiceImpl(
                    GreetingService.Descriptor
                    , CalculatorService.Descriptor
                    , PrimeNumberDecompositionService.Descriptor
                    , SqrtService.Descriptor
                    , DeadlineService.Descriptor
                    , ServerReflection.Descriptor
                    );

                server = new Server
                {
                    Services =
                    {
                        GreetingService.BindService(new GreetingServiceImplementation()),
                        CalculatorService.BindService(new CalculatorServiceImplementation()),
                        PrimeNumberDecompositionService.BindService(new PrimeNumberDecompositionServiceImplementation()),

                        // errors
                        SqrtService.BindService(new SqrtServiceImplementation()),
                        // deadlines
                        DeadlineService.BindService(new DeadlineServiceImplementation()),

                        // reflection-2
                        ServerReflection.BindService(reflectionServiceImpl)
                    },
                    Ports =
                    {
                        await CreateUnsecureServerPort(Host, Port)
                    }
                };

                server.Start();
                Console.WriteLine($"Server is listening on {Port}");
                Console.ReadLine();
            }
            catch (IOException ex)
            {
                Console.WriteLine($"Server failed to start: {ex.Message}");
                throw;
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Server failed: {ex.Message}");
                throw;
            }
            finally
            {
                if (server != null)
                {
                    await server.ShutdownAsync();
                }
            }
        }
Пример #3
0
        static void Main(string[] args)
        {
            Server server = null;

            try
            {
                var reflectionServiceImpl = new ReflectionServiceImpl(GreetingService.Descriptor, ServerReflection.Descriptor);

                var serverCert = File.ReadAllText("ssl/server.crt");
                var serverKey  = File.ReadAllText("ssl/server.key");
                var keypair    = new KeyCertificatePair(serverCert, serverKey);
                var cacert     = File.ReadAllText("ssl/ca.crt");

                var credentials = new SslServerCredentials(
                    new List <KeyCertificatePair>()
                {
                    keypair
                }, cacert, true);

                server = new Server()
                {
                    Services =
                    {
                        GreetingService.BindService(new GreetingServiceImp()),
                        CalculatorService.BindService(new CalculatorServiceImp()),
                        SqrtService.BindService(new SqrtServiceImpl()),
                        GreetDeadlinesService.BindService(new GreetingDeadlinesImpl()),
                        ServerReflection.BindService(reflectionServiceImpl)
                    },

                    Ports = { new ServerPort("localhost", Port, ServerCredentials.Insecure) }
                };

                server.Start();

                Console.WriteLine("The server is listening on the port {0}", Port);
                Console.ReadKey();
            }
            catch (IOException e)
            {
                Console.WriteLine("The server failed to start: ", e.Message);
            }
            finally
            {
                if (server != null)
                {
                    server.ShutdownAsync().Wait();
                }
            }
        }
Пример #4
0
        static void Main(string[] args)
        {
            Server server = null;

            try
            {
                var serverCert = File.ReadAllText("ssl/server.crt");
                var serverKey  = File.ReadAllText("ssl/server.key");
                var keypair    = new KeyCertificatePair(serverCert, serverKey);
                var caCrt      = File.ReadAllText("ssl/ca.crt");

                var credentials = new SslServerCredentials(new List <KeyCertificatePair>()
                {
                    keypair
                }, caCrt, true);

                server = new Server()
                {
                    Services =
                    {
                        GreetingService.BindService(new GreetingServiceImpl()),
                        SumService.BindService(new SumServiceImpl()),
                        PrimeNumbersService.BindService(new PrimeNumbersServiceImpl()),
                        AverageService.BindService(new AverageServiceImpl()),
                        MaxService.BindService(new MaxServiceImpl()),
                        SqrtService.BindService(new SquareRootServiceImpl()),
                        ServerReflection.BindService(new ReflectionServiceImpl(GreetingService.Descriptor, ServerReflection.Descriptor))
                    },

                    Ports = { new ServerPort("localhost", port, credentials) }
                };

                server.Start();
                Console.WriteLine($"Server is listening on port: {port}");
                Console.ReadKey();
            }
            catch (IOException e)
            {
                Console.WriteLine($"Server failed to start - {e.Message}");
                throw;
            }
            finally
            {
                if (server != null)
                {
                    server.ShutdownAsync().Wait();
                }
            }
        }
Пример #5
0
        static void Main(string[] args)
        {
            var serverCert = File.ReadAllText("ssl/server.crt");
            var serverKey  = File.ReadAllText("ssl/server.key");
            var caCert     = File.ReadAllText("ssl/ca.crt");

            var keyPair = new KeyCertificatePair(serverCert, serverKey);

            var credentials = new SslServerCredentials(new List <KeyCertificatePair>()
            {
                keyPair
            }, caCert, true);

            Server server = null;

            try
            {
                server = new Server()
                {
                    Services = { GreetingService.BindService(new GreetingServiceImpl()),
                                 SqrtService.BindService(new SqrtServiceImpl()) },
                    Ports = { new ServerPort("localhost", port, credentials) }
                };

                server.Start();
                Console.WriteLine($"Server listening on port : {port}");
                Console.WriteLine("Press any key ...");
                Console.ReadKey();
            }
            catch (IOException ex)
            {
                Console.WriteLine($"The server failed to start: {ex}");
                throw;
            }
            finally
            {
                if (server != null)
                {
                    server.ShutdownAsync().Wait();
                }
            }
        }