44 lines
1.1 KiB
C++
44 lines
1.1 KiB
C++
#include "libhv_udp_client.h"
|
|
#include "test_struct.h"
|
|
|
|
using namespace hv;
|
|
|
|
int main(int argc, char* argv[]) {
|
|
UdpClient cli;
|
|
static std::string client_ip =
|
|
MyYAMLConfig::Get()["client_ip"].as<std::string>();
|
|
static std::string client_port =
|
|
MyYAMLConfig::Get()["client_port"].as<std::string>();
|
|
int sockfd = cli.createsocket(stoi(client_port), client_ip.c_str());
|
|
if (sockfd < 0) {
|
|
return -20;
|
|
}
|
|
gDebug() << gxt::format("begin listen {}:{}", client_ip, client_port);
|
|
|
|
cli.onMessage = [](const SocketChannelPtr& channel, Buffer* buf) {
|
|
gDebug(buf->size());
|
|
};
|
|
cli.start();
|
|
|
|
// sendto(time) every 3s
|
|
// cli.loop()->setInterval(3000, [&cli](TimerID timerID) {
|
|
// std::string str = gxt::format("{}", gxt::GetTimeUs());
|
|
// cli.sendto(str);
|
|
// });
|
|
|
|
TestStruct test;
|
|
int i = 10000;
|
|
TIME_BEGIN_US();
|
|
while (i--) {
|
|
auto time = gxt::GetTimeUs();
|
|
std::string time_str = std::to_string(time);
|
|
memcpy(test.time, time_str.c_str(), time_str.size());
|
|
test.time[time_str.size()] = '\0';
|
|
cli.sendto(&test, sizeof(test));
|
|
// gxt::SleepUs();
|
|
}
|
|
TIME_END();
|
|
|
|
return 0;
|
|
}
|