Val*_*rov 8 c# server-side grpc .net-5
我们有一个在c# .net 5.0环境上实现的Grpc服务器
public void ConfigureServices(IServiceCollection services)
{
...
services.AddGrpc(o =>
{
o.EnableDetailedErrors = true;
// Small performance benefit to not add catch-all routes to handle UNIMPLEMENTED for unknown services
o.IgnoreUnknownServices = true;
o.Interceptors.Add<CustomInterceptor>();
});
...
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider container, IHostApplicationLifetime lifetime)
{
...
app.UseEndpoints(endpoints =>
{
endpoints.MapGrpcService<GreeterService>();
endpoints.MapGet("/", async context =>
{
await context.Response.WriteAsync("Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909");
});
});
...
}
Run Code Online (Sandbox Code Playgroud)
我们正在使用服务器端流连接来发送客户端通知
public override async Task Start(ConnectorRequest request, IServerStreamWriter<ClientNotification> clientStream,
ServerCallContext serverCallContext)
{
WaitHandle.WaitAny(new[] { context.CancellationToken.WaitHandle });
}
Run Code Online (Sandbox Code Playgroud)
客户端在移动平台上实现。经过测试,我们发现当客户端失去连接(例如关闭 wifi)时,我们没有任何异常或通知。
如何配置服务器在客户端失去连接时中断流连接。可能类似于 keep_alive 设置。我找到了https://github.com/grpc/grpc/blob/master/doc/keepalive.md但我不知道应该在哪里设置它。
| 归档时间: |
|
| 查看次数: |
874 次 |
| 最近记录: |