TEST(Wangle, ClientServerTest) { int port = 1234; // server ServerBootstrap<Pipeline> server; server.childPipeline( std::make_shared<ServerPipelineFactory<std::string, std::string>>()); server.bind(port); // client ClientBootstrap<Pipeline> client; ClientServiceFactory<Pipeline, std::string, std::string> serviceFactory; client.pipelineFactory( std::make_shared<ClientPipelineFactory<std::string, std::string>>()); SocketAddress addr("127.0.0.1", port); client.connect(addr); auto service = serviceFactory(&client).value(); auto rep = (*service)("test"); rep.then([&](std::string value) { EXPECT_EQ("test", value); EventBaseManager::get()->getEventBase()->terminateLoopSoon(); }); EventBaseManager::get()->getEventBase()->loopForever(); server.stop(); }
int main(int argc, char** argv) { folly::Init init(&argc, &argv); ClientBootstrap<EchoPipeline> client; client.group(std::make_shared<folly::IOThreadPoolExecutor>(1)); client.pipelineFactory(std::make_shared<EchoPipelineFactory>()); auto pipeline = client.connect(SocketAddress(FLAGS_host, FLAGS_port)).get(); try { while (true) { std::string line; std::getline(std::cin, line); if (line == "") { break; } pipeline->write(line + "\r\n").get(); if (line == "bye") { pipeline->close(); break; } } } catch (const std::exception& e) { std::cout << exceptionStr(e) << std::endl; } return 0; }