本文整理汇总了C#中Grpc.Core.Server.ShutdownAsync方法的典型用法代码示例。如果您正苦于以下问题:C# Server.ShutdownAsync方法的具体用法?C# Server.ShutdownAsync怎么用?C# Server.ShutdownAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Grpc.Core.Server
的用法示例。
在下文中一共展示了Server.ShutdownAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
const int port = 1337;
var serviceImpl = new PlaygroundServiceImpl(new PersonRepository());
var server = new Grpc.Core.Server
{
Services = { PlaygroundService.BindService(serviceImpl) },
Ports =
{
new ServerPort("0.0.0.0", port, new SslServerCredentials(
new[]
{
new KeyCertificatePair(
File.ReadAllText("certificates\\server.crt"),
File.ReadAllText("certificates\\server.key"))
}))
}
};
server.Start();
Console.WriteLine("RPC server listening on port " + port);
Console.WriteLine("Press any key to stop the server...");
Console.ReadKey();
serviceImpl.Shutdown();
server.ShutdownAsync().Wait();
}
示例2: StartAndShutdownServer
public void StartAndShutdownServer()
{
Server server = new Server();
server.AddListeningPort("localhost", Server.PickUnusedPort);
server.Start();
server.ShutdownAsync().Wait();
GrpcEnvironment.Shutdown();
}
示例3: StartAndShutdownServer
public void StartAndShutdownServer()
{
Server server = new Server
{
Ports = { new ServerPort("localhost", ServerPort.PickUnused, ServerCredentials.Insecure) }
};
server.Start();
server.ShutdownAsync().Wait();
}
示例4: StartAndShutdownServer
public void StartAndShutdownServer()
{
GrpcEnvironment.Initialize();
Server server = new Server();
server.AddListeningPort("localhost:0");
server.Start();
server.ShutdownAsync().Wait();
GrpcEnvironment.Shutdown();
}
示例5: CannotModifyAfterStarted
public void CannotModifyAfterStarted()
{
Server server = new Server
{
Ports = { new ServerPort("localhost", ServerPort.PickUnused, ServerCredentials.Insecure) }
};
server.Start();
Assert.Throws(typeof(InvalidOperationException), () => server.Ports.Add("localhost", 9999, ServerCredentials.Insecure));
Assert.Throws(typeof(InvalidOperationException), () => server.Services.Add(ServerServiceDefinition.CreateBuilder("serviceName").Build()));
server.ShutdownAsync().Wait();
}
示例6: PickUnusedPort
public void PickUnusedPort()
{
Server server = new Server
{
Ports = { new ServerPort("localhost", ServerPort.PickUnused, ServerCredentials.Insecure) }
};
var boundPort = server.Ports.Single();
Assert.AreEqual(0, boundPort.Port);
Assert.Greater(boundPort.BoundPort, 0);
server.Start();
server.ShutdownAsync().Wait();
}
示例7: Main
public static void Main(string[] args)
{
Server server = new Server
{
Services = { Greeter.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();
}
示例8: Main
public static void Main(string[] args)
{
GrpcEnvironment.Initialize();
Server server = new Server();
server.AddServiceDefinition(Greeter.BindService(new GreeterImpl()));
int port = server.AddListeningPort("localhost", 50051);
server.Start();
Console.WriteLine("Greeter server listening on port " + port);
Console.WriteLine("Press any key to stop the server...");
Console.ReadKey();
server.ShutdownAsync().Wait();
GrpcEnvironment.Shutdown();
}
示例9: Main
public static void Main(string[] args)
{
Server server = new Server
{
Services = { Math.BindService(new MathServiceImpl()) },
Ports = { { Host, Port, ServerCredentials.Insecure } }
};
server.Start();
Console.WriteLine("MathServer listening on port " + Port);
Console.WriteLine("Press any key to stop the server...");
Console.ReadKey();
server.ShutdownAsync().Wait();
}
示例10: MainAsync
public static async Task MainAsync()
{
var server = new Server
{
Services = { Greeter.BindService(new GreeterImpl()) },
Ports = { new ServerPort(Host, Port, ServerCredentials.Insecure) }
};
server.Start();
Console.Out.WriteLine("Greeter server listening on port {0}", Port.ToString());
Console.Out.WriteLine("Press any key to stop the server...");
Console.ReadKey();
await server.ShutdownAsync().ConfigureAwait(false);
}
示例11: Main
public static void Main(string[] args)
{
string host = "0.0.0.0";
Server server = new Server();
server.AddServiceDefinition(Math.BindService(new MathServiceImpl()));
int port = server.AddPort(host, 23456, ServerCredentials.Insecure);
server.Start();
Console.WriteLine("MathServer listening on port " + port);
Console.WriteLine("Press any key to stop the server...");
Console.ReadKey();
server.ShutdownAsync().Wait();
GrpcEnvironment.Shutdown();
}
示例12: Main
static void Main(string[] args)
{
var features = RouteGuideUtil.ParseFeatures(RouteGuideUtil.DefaultFeaturesFile);
GrpcEnvironment.Initialize();
Server server = new Server();
server.AddServiceDefinition(RouteGuide.BindService(new RouteGuideImpl(features)));
int port = server.AddListeningPort("localhost", 50052);
server.Start();
Console.WriteLine("RouteGuide server listening on port " + port);
Console.WriteLine("Press any key to stop the server...");
Console.ReadKey();
server.ShutdownAsync().Wait();
GrpcEnvironment.Shutdown();
}
示例13: Main
static void Main(string[] args)
{
const int Port = 50052;
var features = RouteGuideUtil.ParseFeatures(RouteGuideUtil.DefaultFeaturesFile);
Server server = new Server
{
Services = { RouteGuide.BindService(new RouteGuideImpl(features)) },
Ports = { new ServerPort("localhost", Port, ServerCredentials.Insecure) }
};
server.Start();
Console.WriteLine("RouteGuide server listening on port " + Port);
Console.WriteLine("Press any key to stop the server...");
Console.ReadKey();
server.ShutdownAsync().Wait();
}
示例14: Main
static void Main(string[] args)
{
var gameAdminService = new GameAdminServiceServer(
new HardcodedAccountRepository(),
new HardcodedChatMessageRepository());
const int port = 1337;
var rpcServer = new Grpc.Core.Server
{
Services = { GameAdminService.BindService(gameAdminService) },
Ports = { new Grpc.Core.ServerPort("localhost", port, ServerCredentials.Insecure) }
};
rpcServer.Start();
Log("GameAdminService server listening on port " + port);
Log("Press any key to stop the server...");
Console.ReadKey();
Log("GameAdminService shutting down");
rpcServer.ShutdownAsync().Wait();
}
示例15: RunAsync
private async Task RunAsync()
{
string host = "0.0.0.0";
int port = options.DriverPort;
var tcs = new TaskCompletionSource<object>();
var workerServiceImpl = new WorkerServiceImpl(() => { Task.Run(() => tcs.SetResult(null)); });
var server = new Server
{
Services = { WorkerService.BindService(workerServiceImpl) },
Ports = { new ServerPort(host, options.DriverPort, ServerCredentials.Insecure )}
};
int boundPort = server.Ports.Single().BoundPort;
Console.WriteLine("Running qps worker server on " + string.Format("{0}:{1}", host, boundPort));
server.Start();
await tcs.Task;
await server.ShutdownAsync();
}