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) { gflags::ParseCommandLineFlags(&argc, &argv, true); auto serverPool = std::make_shared<SimpleServerPool>(); // A unique BroadcastPipeline for each upstream server to fan-out the // upstream messages to ObservingPipelines corresponding to each client. auto broadcastPipelineFactory = std::make_shared<SimpleBroadcastPipelineFactory>(); // A unique ObservingPipeline is created for each client to subscribe // to the broadcast. auto observingPipelineFactory = std::make_shared<SimpleObservingPipelineFactory>( serverPool, broadcastPipelineFactory); // RoutingDataHandlerFactory for creating the RoutingDataHandler that sets // client IP as the routing data. auto routingHandlerFactory = std::make_shared<ClientIPRoutingDataHandlerFactory>(); ServerBootstrap<SimpleObservingPipeline> server; // AcceptRoutingPipelineFactory for creating accept pipelines hash the // client connection to a worker thread based on client IP. auto acceptPipelineFactory = std::make_shared< AcceptRoutingPipelineFactory<SimpleObservingPipeline, std::string>>( &server, routingHandlerFactory, observingPipelineFactory); server.pipeline(acceptPipelineFactory); server.bind(FLAGS_port); server.waitForStop(); return 0; }
ChannelPtr ServerBuilder::build(const std::string& name, const PipelineInitializer& childPipelineInitializer, const std::string& host, int port, const ChannelOptions& options, const ChannelOptions& childOptions) { if (name.empty()) { LOG_WARN << "parameter error, name should not be empty."; return NullChannel::instance(); } if (bootstraps_.find(name) != bootstraps_.end()) { LOG_WARN << "the " << name << " server type has already registered, "; } ServerBootstrap* bootstrap = new ServerBootstrap( parentEventLoopPool_, childEventLoopPool_); bootstraps_.insert(std::make_pair(name, bootstrap)); setChannelOptions(bootstrap, options, childOptions); if (childPipelineInitializer) { bootstrap->setInitializer(childPipelineInitializer); } else { LOG_WARN << "childPipelineInitializer is empty, channel will not work fine."; return NullChannel::instance(); } bootstrap->setDaemonize(config_.daemonize); return build(bootstrap, host, port); }
int main(int argc, char** argv) { gflags::ParseCommandLineFlags(&argc, &argv, true); ServerBootstrap<SerializePipeline> server; server.childPipeline(std::make_shared<RpcPipelineFactory>()); server.bind(FLAGS_port); server.waitForStop(); return 0; }
int main(int argc, char** argv) { folly::Init init(&argc, &argv); ServerBootstrap<EchoPipeline> server; server.childPipeline(std::make_shared<EchoPipelineFactory>()); server.bind(FLAGS_port); server.waitForStop(); return 0; }
int main(int argc, char** argv) { gflags::ParseCommandLineFlags(&argc, &argv, true); ServerBootstrap<DefaultPipeline> server; server.childPipeline(std::make_shared<ProxyFrontendPipelineFactory>( SocketAddress(FLAGS_remote_host, FLAGS_remote_port))); server.bind(FLAGS_port); server.waitForStop(); return 0; }
int main(int argc, char** argv) { folly::Init init(&argc, &argv); ServerBootstrap<DefaultPipeline> server; server.childPipeline(std::make_shared<ProxyFrontendPipelineFactory>( SocketAddress(FLAGS_remote_host, FLAGS_remote_port))); server.bind(FLAGS_port); server.waitForStop(); return 0; }
int main(int argc, char** argv) { gflags::ParseCommandLineFlags(&argc, &argv, true); auto routingHandlerFactory = std::make_shared<NaiveRoutingDataHandlerFactory>(); auto childPipelineFactory = std::make_shared<ServerPipelineFactory>(); ServerBootstrap<DefaultPipeline> server; server.pipeline( std::make_shared<AcceptRoutingPipelineFactory<DefaultPipeline, char>>( &server, routingHandlerFactory, childPipelineFactory)); server.bind(FLAGS_port); server.waitForStop(); return 0; }