예제 #1
0
        public static async Task Main(string[] args)
        {
            var discover = new DiscoverMessage();

            Console.WriteLine("Welcome!");
            Console.WriteLine("Your ID: " + discover.SourceId);
            Console.WriteLine("Your Time: " + discover.Time);

            var factory = new ConnectionFactory()
            {
                HostName = "localhost",
            };

            using (var connection = factory.CreateConnection())
            {
                using (var channel = connection.CreateModel())
                {
                    var client       = new RPCClient(channel);
                    var cTokenSource = new CancellationTokenSource();
                    cTokenSource.CancelAfter(5000);

                    try
                    {
                        Console.WriteLine("Looking for the master...");
                        await client.CallAsync(discover, cTokenSource.Token);
                    }
                    catch (OperationCanceledException)
                    {
                        new RPCServer(channel, discover.SourceId, DateTime.Now);
                        Console.WriteLine("Master not found. You're the master now.");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }

                    while (true)
                    {
                        var command = Console.ReadLine();

                        if (command == "quit")
                        {
                            break;
                        }
                        else
                        {
                            Console.WriteLine("Invalid command.");
                        }
                    }
                }
            }

            Console.WriteLine("Shutting down.");
            Thread.Sleep(1500);
        }
예제 #2
0
    private static async Task InvokeAsync(string n)
    {
        var rpcClient = new RPCClient();

        Console.WriteLine(" [x] Requesting fib({0})", n);
        var response = await rpcClient.CallAsync(n.ToString());

        Console.WriteLine(" [.] Got '{0}'", response);

        rpcClient.Close();
    }