private void SendUdpMessage() { var binarySender = new UdpBinarySender(this.destination, this.port); Thread sendMessageThread = new Thread(() => binarySender.SendMessage(GetDataFromFile(TcpBinaryFilePath))); sendMessageThread.Start(); }
public void StructureSendAndReceive() { TestSt toSendSt; toSendSt.intval = 99; toSendSt.floatval = 98.7f; toSendSt.mojiretsu = "mogemoge!"; toSendSt.intarray = new int[4] { 1, 2, 3, 4 }; using RTCLib.Comm.UdpBinarySender <TestSt> sender = new UdpBinarySender <TestSt>("127.0.0.1", 30001); using RTCLib.Comm.UdpBinaryReceiver <TestSt> receiver = new UdpBinaryReceiver <TestSt>(); receiver.Open(30001); TestSt receivedData = default; bool received = false; receiver.OnDataReceived += dataReceived => { receivedData = dataReceived; received = true; }; // send sender.Send(toSendSt); // 1 sec wait for (int i = 0; i < 100; i++) { Thread.Sleep(10); if (received) { break; } } if (received) { // check contents toSendSt.IsStructuralEqual(receivedData); } else { Assert.True(false); } sender.Close(); receiver.Close(); }