コード例 #1
0
ファイル: WalletClient.cs プロジェクト: decred/Paymetheus
        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
0
        public async Task <string[]> GenerateSeed(string aezeedPassphrase = default(string))
        {
            var genSeedResponse = new GenSeedResponse();

            try
            {
                walletRpcChannel = new Grpc.Core.Channel(HostName, new SslCredentials(Cert));
                walletUnlocker   = new WalletUnlocker.WalletUnlockerClient(walletRpcChannel);
                await walletRpcChannel.ConnectAsync();

                var genSeedRequest = new GenSeedRequest();
                if (!string.IsNullOrEmpty(aezeedPassphrase))
                {
                    genSeedRequest.AezeedPassphrase = ByteString.CopyFromUtf8(aezeedPassphrase);
                }
                genSeedResponse = await walletUnlocker.GenSeedAsync(genSeedRequest);

                walletRpcChannel.ShutdownAsync().Wait();
            } catch (RpcException e)
            {
                walletRpcChannel.ShutdownAsync().Wait();
                return(new string[] { e.Status.Detail });
            }
            return(genSeedResponse.CipherSeedMnemonic.ToArray());;
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: mleenhardt/rpc-benchmark
        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();
        }
コード例 #4
0
ファイル: HubConnector.cs プロジェクト: y-tomita/UnityGame
        /// <summary>
        /// 接続開始
        /// </summary>
        /// <param name="receiver"></param>
        /// <param name="ipAddr"></param>
        /// <param name="port"></param>
        /// <returns></returns>
        public async UniTask ConnectStartAsync()
        {
            while (!cancellationTokenSource.IsCancellationRequested)
            {
                try
                {   // 本当にサーバーに接続できるか確認
                    await channel.ConnectAsync(DateTime.UtcNow.AddSeconds(5));

                    Debug.Log("connecting to the server ... ");
                    ServerImpl = await StreamingHubClient.ConnectAsync <TServer, TClient>(channel, ClientImpl, cancellationToken : cancellationTokenSource.Token);

                    executeDisconnectEventWaiterAsync(ServerImpl).Forget();
                    Debug.Log("established connect");
                    break;
                }
                catch (TaskCanceledException)
                {
                }
                catch (OperationCanceledException e)
                {
                    Debug.LogWarning(e);
                    throw new OperationCanceledException();
                }
                catch (Exception e)
                {
                    Debug.LogError(e);
                }

                Debug.Log("Retry after 2 seconds");
                await UniTask.Delay(2 * 1000, cancellationToken : cancellationTokenSource.Token);
            }
        }
コード例 #5
0
 async void TryConnecting()
 {
     Debug.Log(rpcChannel.State);
     if (rpcChannel.State == ChannelState.Ready)
     {
         CancelInvoke("TryConnecting");
         return;
     }
     await rpcChannel.ConnectAsync();
 }
コード例 #6
0
ファイル: WalletClient.cs プロジェクト: tuxcanfly/Paymetheus
        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);
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: Ahmed-Taw/gRpc-demo
        static async Task Main(string[] args)
        {
            Grpc.Core.Channel channel = new Grpc.Core.Channel(connection, Grpc.Core.ChannelCredentials.Insecure);

            await channel.ConnectAsync().ContinueWith((task) =>
            {
                if (task.Status == System.Threading.Tasks.TaskStatus.RanToCompletion)
                {
                    Console.WriteLine("The client connected to server: " + connection);
                }
                else
                {
                    Console.WriteLine(task.Status.ToString());
                }
            });

            var client = new Greeting.GreetingService.GreetingServiceClient(channel);  //new DummyService.DummyServiceClient(channel);

            //var greetingObject = new Greeting.Greeting() { FirstName = "Ahmed", LastName = "Tawfik" };
            //var responseTask = client.GreetAsync(new Greeting.GreetingRequest() { Greeting =  greetingObject}).ResponseAsync;
            //Console.WriteLine(responseTask.Result.Result);


            var greetingObject = new Greeting.Greeting()
            {
                FirstName = "Ahmed", LastName = "Tawfik"
            };
            var responseStream = client.GreetManyTimes(new Greeting.GreetManyTimesRequest()
            {
                Greeting = greetingObject
            });

            while (await responseStream.ResponseStream.MoveNext())
            {
                Console.WriteLine(responseStream.ResponseStream.Current.Result);

                await Task.Delay(2000);
            }


            channel.ShutdownAsync().Wait();
            Console.ReadKey();
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: mleenhardt/grpc-demo
        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();
        }
コード例 #9
0
        public async Task <string> UnlockWallet(string walletPassword, string[] mnemonic)
        {
            walletRpcChannel = new Grpc.Core.Channel(HostName, new SslCredentials(Cert));
            walletUnlocker   = new WalletUnlocker.WalletUnlockerClient(walletRpcChannel);
            await walletRpcChannel.ConnectAsync();

            var initWalletRequest = new InitWalletRequest();

            initWalletRequest.WalletPassword = ByteString.CopyFromUtf8(walletPassword);
            initWalletRequest.CipherSeedMnemonic.AddRange(mnemonic);
            try
            {
                var initWalletResponse = await walletUnlocker.InitWalletAsync(initWalletRequest);

                walletRpcChannel.ShutdownAsync().Wait();


                return("unlocked");
            } catch (RpcException e)
            {
                if (e.Status.Detail == "wallet already exists")
                {
                    var unlockWalletRequest = new UnlockWalletRequest()
                    {
                        WalletPassword = ByteString.CopyFromUtf8(walletPassword)
                    };
                    var unlockWalletResponse = await walletUnlocker.UnlockWalletAsync(unlockWalletRequest);

                    walletRpcChannel.ShutdownAsync().Wait();


                    return("unlocked");
                }
                Debug.Log(e);
            }
            walletRpcChannel.ShutdownAsync().Wait();

            return("not unlocked");
        }
コード例 #10
0
 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());
 }