示例#1
0
文件: Rpc.cs 项目: dbrgn/pi-vote
        public void RpcTest()
        {
            TcpRpcServer server = new TcpRpcServer(new EchoServer());
              server.Start();

              CertificateStorage storage = new CertificateStorage();
              TcpRpcClient client = new TcpRpcClient();

              client.Connect(new IPEndPoint(IPAddress.Loopback, 4242));

              Assert.IsTrue(client.Connected);

              var request = new EchoRequest(Guid.NewGuid(), "hello");

              var responseData = client.Execute(request.ToBinary());

              var response = Serializable.FromBinary<EchoResponse>(responseData);

              Assert.AreEqual(request.RequestId, response.RequestId);
              Assert.AreEqual("hello", response.Message);

              client.Disconnect();

              Assert.IsFalse(client.Connected);

              server.Stop();
        }
示例#2
0
        public static void Main(string[] args)
        {
            Console.WriteLine("PiVote TCP RPC Server");

              AssemblyName programName = Assembly.GetExecutingAssembly().GetName();
              AssemblyName libraryName = typeof(VotingRpcServer).Assembly.GetName();

              Console.WriteLine("Program version {0}", programName.Version.ToString());
              Console.WriteLine("Library version {0}", libraryName.Version.ToString());
              Console.WriteLine();

              if (args.Length >= 1 && args[0] == "wait")
              {
            Console.Write("Waiting to start...");
            Thread.Sleep(10000);
            Console.WriteLine("Go");
              }

              RpcServer = new VotingRpcServer();
              TcpServer = new TcpRpcServer(RpcServer);

              try
              {
            TcpServer.Start();
              }
              catch (Exception exception)
              {
            TcpServer.Logger.Log(LogLevel.Error, "Start failed with exception {0}", exception.Message);

            Console.WriteLine();
            Console.WriteLine(exception.ToString());
              }

              try
              {
            while (true)
            {
              Thread.Sleep(1000);
            }
              }
              catch (Exception exception)
              {
            TcpServer.Logger.Log(LogLevel.Error, "Server failed with exception {0}. Trying to restart it.", exception.Message);

            Process.Start(Environment.GetCommandLineArgs()[0], "wait");
            Environment.FailFast("Server failed");
              }
        }
示例#3
0
        public void VotingServerTest()
        {
            TcpRpcServer server = new TcpRpcServer(new VotingRpcServer());
              server.Start();

              CertificateStorage storage = new CertificateStorage();
              TcpRpcClient client = new TcpRpcClient();

              client.Connect(new IPEndPoint(IPAddress.Loopback, 4242));
              Assert.IsTrue(client.Connected);

              VotingRpcProxy proxy = new VotingRpcProxy(client);
              proxy.Start();

              var ids = proxy.FetchVotingIds();

              proxy.Stop();

              client.Disconnect();
              Assert.IsFalse(client.Connected);

              server.Stop();
        }