Example #1
0
        private static async Task <HelloChatty.HelloChattyClient> ConnectProtoClient(string serverAddress)
        {
            var key        = System.IO.File.ReadAllText(client_private_key_file);
            var cert       = System.IO.File.ReadAllText(client_certificate_file);
            var serverCert = System.IO.File.ReadAllText(server_certificate_file);

            var creds = new SslCredentials(
                serverCert, new KeyCertificatePair(key, cert)
                );

            var rpcChannel = new Channel(serverAddress, creds,
                                         new List <ChannelOption> {
                // docs about keeping grpc connection alive: https://github.com/grpc/grpc/blob/master/doc/keepalive.md
                // the mappings of the fields are in file grpc/include/grpc/impl/codegen/grpc_types.h in the official grpc core repo https://github.com/grpc/grpc
                new ChannelOption("grpc.keepalive_time_ms", 1000),           // keepalive ping every X ms
                new ChannelOption("grpc.keepalive_timeout_ms", 10 * 1000),   // peer must reply to our ping within this
                new ChannelOption("grpc.keepalive_permit_without_calls", 1), // allow keepalive without calls at all
                // new ChannelOption ( "grpc.http2.max_pings_without_data", 0 ), // server-only setting
                // new ChannelOption ( "grpc.http2.min_ping_interval_without_data_ms", 1000), // server-only setting
                new ChannelOption("grpc.http2.max_ping_strikes", 1),
            }
                                         );
            var rpcClient = new HelloChatty.HelloChattyClient(rpcChannel);

            await rpcChannel.ConnectAsync();

            if (rpcChannel.State == ChannelState.Ready)
            {
                return(rpcClient);
            }
            throw new Exception($@"For unknown reason, the channel state is still {rpcChannel.State}");
        }
Example #2
0
 public ChatConsoleClient(HelloChatty.HelloChattyClient client)
 {
     _client = new HelloChattyClient(client);
 }
Example #3
0
 public HelloChattyClient(HelloChatty.HelloChattyClient client)
 {
     _rpcClient = client;
 }