#include "Test.h" #include "TCP.h" using namespace std; void Tcp_Test() { // AsyncTCPClient client; // client.connect("127.0.0.1", 9999); // client.start_async(); // while (client.is_connected()) { // std::vector str; // if (client.try_pop(str)) { // cout << string(str.begin(), str.end()) << endl; // } // } try { TCPClient client; client.connect("192.168.80.1", 9999); while (client.is_connected()) { vector buffer(1024); auto size = client.receive(buffer.data(), buffer.size()); string info; if (size > 0) { info = std::string(buffer.begin(), buffer.begin() + static_cast(size)); cout << info << endl; } if (info.find("stop") != string::npos) { client.close_socket(); } } } catch (std::exception &e) { cerr << e.what() << endl; } TCPServer tcpServer; tcpServer.listen(9998); auto client = tcpServer.accept(); while (client->is_connected()) { client->send("hello"); vector buffer(1024); auto size = client->receive(buffer.data(), buffer.size()); string info; if (size > 0) { info = std::string(buffer.begin(), buffer.begin() + static_cast(size)); cout << info << endl; } if (info.find("stop") != string::npos) { client->close_socket(); } } }