MyLib
This commit is contained in:
29
Test/UdpTest.cpp
Normal file
29
Test/UdpTest.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
#include "Test.h"
|
||||
#include "UDP.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
void Udp_Test() {
|
||||
//UDP
|
||||
uint16_t port = 8900;
|
||||
UDPReceiver udpReceiver(port);
|
||||
udpReceiver.start_receiving([](const std::vector<uint8_t> &date, sockaddr_in sockAdd, socklen_t socklen){
|
||||
string da(date.begin(), date.end());
|
||||
cout << inet_ntoa(sockAdd.sin_addr) << ":" << ntohs(sockAdd.sin_port) << endl;
|
||||
cout << da << endl;
|
||||
});
|
||||
UDPSender udpSenderA(udpReceiver.sockfd_);
|
||||
udpSenderA.set_destination("127.0.0.1", 8200);
|
||||
UDPSender udpSenderB(udpReceiver.sockfd_);
|
||||
udpSenderB.set_destination("127.0.0.1", 8201);
|
||||
UDPSender udpSenderC(udpReceiver.sockfd_);
|
||||
udpSenderC.set_destination("127.0.0.1", 8200);
|
||||
|
||||
|
||||
while (true) {
|
||||
udpSenderA.send("helloA");
|
||||
udpSenderB.send("B");
|
||||
udpSenderC.send("C");
|
||||
_sleep(5000);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user