当前位置: 首页>>代码示例>>C#>>正文


C# Channel.ConnectAsync方法代码示例

本文整理汇总了C#中Grpc.Core.Channel.ConnectAsync方法的典型用法代码示例。如果您正苦于以下问题:C# Channel.ConnectAsync方法的具体用法?C# Channel.ConnectAsync怎么用?C# Channel.ConnectAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Grpc.Core.Channel的用法示例。


在下文中一共展示了Channel.ConnectAsync方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConnectAsync

        public static async Task<WalletClient> ConnectAsync(string networkAddress, string rootCertificate)
        {
            if (networkAddress == null)
                throw new ArgumentNullException(nameof(networkAddress));
            if (rootCertificate == null)
                throw new ArgumentNullException(nameof(rootCertificate));

            var channel = new Channel(networkAddress, new SslCredentials(rootCertificate));
            var deadline = DateTime.UtcNow.AddSeconds(3);
            try
            {
                await channel.ConnectAsync(deadline);
            }
            catch (TaskCanceledException)
            {
                await channel.ShutdownAsync();
                throw new ConnectTimeoutException();
            }

            // Ensure the server is running a compatible version.
            var versionClient = new VersionService.VersionServiceClient(channel);
            var response = await versionClient.VersionAsync(new VersionRequest(), deadline: deadline);
            var serverVersion = new SemanticVersion(response.Major, response.Minor, response.Patch);
            SemanticVersion.AssertCompatible(RequiredRpcServerVersion, serverVersion);

            return new WalletClient(channel);
        }
开发者ID:decred,项目名称:Paymetheus,代码行数:27,代码来源:WalletClient.cs

示例2: Main

        static void Main(string[] args)
        {
            var rpcChannel = new Channel("localhost:1337", ChannelCredentials.Insecure);
            var rpcClient = new BenchmarkServiceClient(BenchmarkService.NewClient(rpcChannel));
            rpcChannel.ConnectAsync().Wait();

            _timer.Elapsed += (s, e) =>
            {
                var lastMinuteCallCount = Interlocked.Exchange(ref _lastMinuteCallCount, 0);
                Console.WriteLine($"{DateTime.Now} -- {lastMinuteCallCount} ops/sec");
            };
            _timer.Start();

            for (int i = 0; i < CALL_COUNT; i++)
            {
                rpcClient.Operation(new ServiceRequest { Id = 10 });
                Interlocked.Increment(ref _lastMinuteCallCount);
            }

            //for (int i = 0; i < CALL_COUNT; i++)
            //{
            //    rpcClient.OperationAsync(new ServiceRequest { Id = 10 }).ContinueWith(t => Interlocked.Increment(ref _lastMinuteCallCount));
            //}

            //rpcClient.OperationStreamAsync(() => Interlocked.Increment(ref _lastMinuteCallCount)).Wait();
        }
开发者ID:mleenhardt,项目名称:rpc-benchmark,代码行数:26,代码来源:Program.cs

示例3: ConnectAsync

        public static async Task<WalletClient> ConnectAsync(string networkAddress)
        {
            if (networkAddress == null)
                throw new ArgumentNullException(nameof(networkAddress));

            var rootCertificate = await TransportSecurity.ReadCertificate();
            var channel = new Channel(networkAddress, new SslCredentials(rootCertificate));
            var deadline = DateTime.UtcNow.AddSeconds(1);
            try
            {
                await channel.ConnectAsync(deadline);
            }
            catch (TaskCanceledException)
            {
                await channel.ShutdownAsync();
                throw new ConnectTimeoutException();
            }
            return new WalletClient(channel);
        }
开发者ID:tuxcanfly,项目名称:Paymetheus,代码行数:19,代码来源:WalletClient.cs

示例4: Main

        static void Main(string[] args)
        {
            var rpcChannel = new Channel("localhost:1337", ChannelCredentials.Insecure);
            var rpcClient = new GameAdminServiceClient(GameAdminService.NewClient(rpcChannel));

            rpcChannel.ConnectAsync().Wait();
            Log($"GameAdminServiceClient connected to {rpcChannel.ResolvedTarget}, channel state = {rpcChannel.State}");

            rpcClient.GetAccountAsync(1234).Wait();
            rpcClient.GetChatHistoryAsync(Enumerable.Range(1, 2), CancellationToken.None).Wait();
            rpcClient.ListenChatAsync(1234).Wait();
            rpcClient.ChatAsync().Wait();

            Log($"GameAdminServiceClient disconnecting from {rpcChannel.ResolvedTarget}, channel state = {rpcChannel.State}", true);
            rpcChannel.ShutdownAsync().Wait();

            Console.WriteLine("Press any key to stop the client...");
            Console.ReadKey();
        }
开发者ID:mleenhardt,项目名称:grpc-demo,代码行数:19,代码来源:Program.cs

示例5: OperationsThrowAfterShutdown

 public async Task OperationsThrowAfterShutdown()
 {
     var channel = new Channel("localhost", ChannelCredentials.Insecure);
     await channel.ShutdownAsync();
     Assert.ThrowsAsync(typeof(ObjectDisposedException), async () => await channel.WaitForStateChangedAsync(ChannelState.Idle));
     Assert.Throws(typeof(ObjectDisposedException), () => { var x = channel.ResolvedTarget; });
     Assert.ThrowsAsync(typeof(TaskCanceledException), async () => await channel.ConnectAsync());
 }
开发者ID:ConfusedReality,项目名称:pkg_network_grpc,代码行数:8,代码来源:ChannelTest.cs


注:本文中的Grpc.Core.Channel.ConnectAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。