#include #include #include #include #include #include using namespace trantor; int main() { trantor::Logger::setLogLevel(trantor::Logger::TRACE); LOG_DEBUG << "TcpClient class test!"; EventLoop loop; InetAddress serverAddr("127.0.0.1", 8848); trantor::TcpClient client(&loop, serverAddr, "tcpclienttest"); client.setConnectionCallback([=, &loop](const TcpConnectionPtr &conn) { if (conn->connected()) { std::string str = "GET /pipe HTTP/1.1\r\n" "\r\n" "GET /pipe HTTP/1.1\r\n" "\r\n" "GET /pipe HTTP/1.1\r\n" "\r\n" "GET /pipe HTTP/1.1\r\n" "\r\n" "GET /pipe HTTP/1.1\r\n" "\r\n" "GET /pipe HTTP/1.1\r\n" "\r\n" "GET /pipe HTTP/1.1\r\n" "\r\n" "GET /pipe HTTP/1.1\r\n" "\r\n"; for (int i = 0; i < 4; i++) conn->send(str); } else { loop.quit(); } }); client.setMessageCallback([=](const TcpConnectionPtr &conn, MsgBuffer *buf) { LOG_DEBUG << string_view(buf->peek(), buf->readableBytes()); buf->retrieveAll(); }); client.connect(); loop.loop(); }