本文整理汇总了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);
}
示例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();
}
示例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);
}
示例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();
}
示例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());
}