public static async Task MainInternal(string[] args) { var host = args.Length > 0 ? args[0] : "localhost"; var count = args.Length > 1 ? int.Parse(args[1]) : 5; var random = new Random(); var BasePort = int.Parse(ConfigurationManager.AppSettings["BasePort"]); var impl = new MyServiceImpl(); var services = new[] { MyService.BindService(impl), }; var server = GrpcHelper.StartServer(services, ServerCredentials.Insecure, host, BasePort, count * 2, out var port); var id = $"{host}:{port}"; Logger.Id = id; Console.Title = id; Log($"Listening on {host}:{port}"); var ports = Enumerable.Range(BasePort, count).Take(count).Where(p => p != port).ToArray(); var clients = ports.ToDictionary(p => p, p => CreateClient(host, p)); while (true) { var tasks = clients.Select(p => TestAsync(id, $"{host}:{p.Key}", p.Value)).ToArray(); await Task.WhenAll(tasks); await Task.Delay(random.Next(5000, 10000)); } }
static void Main(string[] args) { var server = new Server(); server.Ports.Add(new ServerPort("127.0.0.1", 8888, SslServerCredentials.Insecure)); server.Services.Add(MyService.BindService(new ServiceImplementation())); server.Start(); System.Console.WriteLine("Server Running ..."); System.Console.ReadLine(); }
static void RunServer() { int port = 50051; var server = new Grpc.Core.Server() { Services = { MyService.BindService(new MyServiceImpl()) }, Ports = { new ServerPort("localhost", port, ServerCredentials.Insecure) } }; server.Start(); Console.WriteLine($"Server listening on port {port}"); Console.WriteLine("Press any key to stop the server"); Console.ReadKey(); Console.WriteLine("Shutting down..."); server.ShutdownAsync().Wait(); }
static void Main(string[] args) { // This switch must be set before creating the GrpcChannel/HttpClient. AppContext.SetSwitch( "System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); //var features = RouteGuideUtil.ParseFeatures(RouteGuideUtil.DefaultFeaturesFile); Server server = new Server { Services = { MyService.BindService(new MyServiceServer()) }, Ports = { new ServerPort("127.0.0.1", 50051, ServerCredentials.Insecure) } }; server.Start(); Console.WriteLine("RouteGuide server listening on port " + 50051); Console.WriteLine("Press any key to stop the server..."); Console.ReadKey(); server.ShutdownAsync().Wait(); Console.WriteLine("Hello World!"); }