private static void Main() { using (var testTcpClient = new TestServiceClient(Protocol.Tcp, IPAddress.Loopback)) { for (int i = 0; i < 10; i++) { var arg = new PingStruct { Value = i }; PingStruct result = testTcpClient.Ping_1(arg); Console.WriteLine($"PING1 TCP - Sent: {i}, Received: {result.Value}"); result = testTcpClient.Ping2_2(arg); Console.WriteLine($"PING2 TCP - Sent: {i}, Received: {result.Value}"); } } using var testUdpClient = new TestServiceClient(Protocol.Udp, IPAddress.Loopback); for (int i = 0; i < 10; i++) { var arg = new PingStruct { Value = i }; PingStruct result = testUdpClient.Ping_1(arg); Console.WriteLine($"PING1 UDP - Sent: {i}, Received: {result.Value}"); result = testUdpClient.Ping2_2(arg); Console.WriteLine($"PING2 UDP - Sent: {i}, Received: {result.Value}"); } }
private void LegAddressradDropDownList_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode != Keys.Up && e.KeyCode != Keys.Down) { Thread myThread = new Thread(legal_addres_rgDropDownList_fias); PingStruct ps = new PingStruct(); ps.addr = this.LegAddressradDropDownList.Text; myThread.Start(ps); LegAddressradDropDownList.ShowDropDown(); } }
public void TcpConnection() { const int Program = 12; const int Version = 13; const int Procedure = 14; var receivedCallChannel = new Channel <ReceivedRpcCall>(); void Dispatcher(ReceivedRpcCall call) { // To assert it on the main thread receivedCallChannel.Send(call); var pingStruct = new PingStruct(); call.RetrieveCall(pingStruct); call.Reply(pingStruct); } var serverSettings = new ServerSettings { Logger = new TestLogger("TCP Server"), Port = Port }; using var server = new RpcTcpServer(this.ipAddress, Program, new[] { Version }, Dispatcher, serverSettings); server.Start(); for (int i = 0; i < 10; i++) { var clientSettings = new ClientSettings { Port = Port, Logger = new TestLogger("TCP Client") }; using var client = new RpcTcpClient(this.ipAddress, Program, Version, clientSettings); var argument = new PingStruct { Value = i }; var result = new PingStruct(); client.Call(Procedure, Version, argument, result); Assert.That(receivedCallChannel.TryReceive(TimeSpan.FromSeconds(10), out ReceivedRpcCall receivedCall)); Assert.That(receivedCall.Procedure, Is.EqualTo(Procedure)); Assert.That(receivedCall.Version, Is.EqualTo(Version)); Assert.That(argument.Value, Is.EqualTo(result.Value)); } }
public void SendAndReceiveData() { IPAddress ipAddress = IPAddress.Loopback; const int Program = 12; const int Version = 13; const int Procedure = 14; var receivedCallChannel = new Channel <ReceivedRpcCall>(); void Dispatcher(ReceivedRpcCall call) { // To assert it on the main thread receivedCallChannel.Send(call); var pingStruct = new PingStruct(); call.RetrieveCall(pingStruct); call.Reply(pingStruct); } var serverSettings = new ServerSettings { Logger = new TestLogger("UDP Server"), Port = Port }; using var server = new RpcUdpServer(ipAddress, Program, new[] { Version }, Dispatcher, serverSettings); server.Start(); var clientSettings = new ClientSettings { Port = Port, Logger = new TestLogger("UDP Client") }; using var client = new RpcUdpClient(ipAddress, Program, Version, clientSettings); var argument = new PingStruct { Value = 42 }; var result = new PingStruct(); client.Call(Procedure, Version, argument, result); Assert.That(receivedCallChannel.TryReceive(TimeSpan.FromSeconds(10), out ReceivedRpcCall receivedCall)); Assert.That(receivedCall.Procedure, Is.EqualTo(Procedure)); Assert.That(receivedCall.Version, Is.EqualTo(Version)); Assert.That(receivedCall.Caller, Is.Not.Null); Assert.That(argument.Value, Is.EqualTo(result.Value)); }
private void LegAddressradDropDownList_TextChanged(object sender, EventArgs e) { try { if ((LegAddressradDropDownList.Text.Length > 3) && (legal_address_rgDropDownListText != LegAddressradDropDownList.Text)) { legal_address_rgDropDownListText = LegAddressradDropDownList.Text; Thread myThread = new Thread(legal_addres_rgDropDownList_fias); PingStruct ps = new PingStruct(); ps.addr = LegAddressradDropDownList.Text; myThread.Start(ps); } } catch { } }
public void OneClient(Protocol protocol) { var clientSettings = new ClientSettings { Logger = new TestLogger("RPC Client"), PortMapperPort = PortMapperPort }; using var client = new TestServiceClient(protocol, IPAddress.Loopback, clientSettings); for (int i = 0; i < 100; i++) { PingStruct result = client.Ping_1(new PingStruct { Value = i }); Assert.That(result.Value, Is.EqualTo(i)); } }
public void legal_addres_rgDropDownList_fias(object obj) { try { if (obj.GetType() != typeof(PingStruct)) { return; } PingStruct ps = (PingStruct)obj; SuggestClient api = null; var token = Properties.Settings.Default.FIASToken; var query = ps.addr; try { Guid guidResult = Guid.Parse(query); api = new SuggestClient(token, "dadata.ru", true); } catch { api = new SuggestClient(token, "dadata.ru"); } var response = api.QueryAddress(query); BeginInvoke(new MethodInvoker(() => { if (response.suggestionss != null) { string s = LegAddressradDropDownList.Text; this.LegAddressradDropDownList.Items.Clear(); suggs = response.suggestionss; foreach (var i in response.suggestionss) { this.LegAddressradDropDownList.Items.Add(i.value); } LegAddressradDropDownList.Text = s; LegAddressradDropDownList.SelectionStart = s.Length; } })); } catch { } }
public override PingStruct Ping2_2(Caller caller, PingStruct arg1) => arg1;
public override PingStruct Ping2_2(Caller caller, PingStruct arg1) { TheLogger.Info($"{caller} PING2({arg1.Value})"); return(arg1); }