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(); }
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(); }
/// <summary> /// Create a new voter client. /// </summary> /// <param name="certificateStorage">Certificate storage</param> public VotingClient(CertificateStorage certificateStorage) { this.certificateStorage = certificateStorage; this.client = new TcpRpcClient(); this.operations = new Queue<Operation>(); this.run = true; this.masterThread = new Thread(RunMaster); this.masterThread.Start(); }
private void ConnectPiVote() { if (this.valid) { try { this.client = new TcpRpcClient(); this.client.Connect(new IPEndPoint(IPAddress.Loopback, 4242)); this.proxy = new VotingRpcProxy(client); } catch (Exception exception) { this.error = exception.Message; this.message = "Pi-Vote server connection failed."; this.valid = false; } } }
private bool ConnectToServer() { table.AddHeaderRow(2, "Pi-Vote Server"); string fileName = Path.Combine(Request.PhysicalApplicationPath, "server.pi-cert"); if (File.Exists(fileName)) { this.serverCertificate = Serializable.Load<ServerCertificate>(fileName); } else { table.AddRow("Connection:", "N/A"); table.AddRow(string.Empty, "Server certifcate not found."); table.AddSpaceRow(2, 32); return false; } try { this.client = new TcpRpcClient(); this.client.Connect(new IPEndPoint(IPAddress.Loopback, 4242)); this.proxy = new VotingRpcProxy(client); } catch { table.AddRow("Connection:", "Failed"); table.AddRow(string.Empty, "Pi-Vote server connection failed."); table.AddSpaceRow(2, 32); return false; } try { var result = proxy.FetchCertificateStorage(); this.certificateStorage = new CertificateStorage(); this.certificateStorage.TryLoadRoot(Request.PhysicalApplicationPath); this.certificateStorage.Add(result.First); } catch { table.AddRow("Connection:", "Failed"); table.AddRow(string.Empty, "Cannot download certificate storage."); table.AddSpaceRow(2, 32); return false; } table.AddRow("Connection:", "Ok"); table.AddSpaceRow(2, 32); return true; }