2 defines the connector, acceptor and service three roles, connector is used to actively establish a TCP connection; acceptor passively receives and establishes a TCP connection, service is defined as a service logic module (based on the POSA2 acceptor-connector pattern)
5 provides application layer information encapsulation, can be used as send and receive buffers, support serialization and deserialization (continuous to be optimization)
Using the new features of C++ 11(14) (prefect-forward, universal reference, move-semantic, smart-pointer)
i32 main(i32 argc, char* argv[])
{
if (argc < 3)
{
std::cout << "usage: test_cute_connector <host> <port>" << std::endl;
return 0;
}
// init reactor
cute_reactor reactor;
reactor.init();
// init connector and try connect to server
auto connector = std::make_shared<cute_connector<my_service_handler>>();
cute_net_addr addr(argv[1], std::atoi(argv[2]));
connector->connect(addr, &reactor);
// go
reactor.run_loop();
}
i32 main()
{
// init reactor
cute_reactor reactor;
reactor.init();
// init acceptor
auto acceptor = std::make_shared<cute_acceptor<echo_service_handler>>();
cute_net_addr addr("0.0.0.0", 11000);
acceptor->open(addr, &reactor);
// run reactor event demultiplex and dispatch
reactor.run_loop();
}
cd <setup_folder>/cute
cmake -DCMAKE_BUILD_TYPE=Debug .
make
./sample/server &
./sample/client 127.0.0.1 11000 2