本文为初见,Netplus快速开始之PingPong Example系列第四篇
启动一个服务 (server端):
- 实现自己的Channel Handler
- 在tcp://ip:port处监听服务
- 当Accept成功新的Channel后,为Channel添加Channel Handler
Code Example:
这个例子,我们暂时使用一个Netplus自带的 channel handler。
netp::handler:echo:当收到来自对端的消息的时候,原样回复。
在这个例子中, 我们监听tcp://0.0.0.0:22310,当收新的连接Accept成功后,为其添加一个叫echo的handler
NRP<netp::channel_listen_promise> f_listen = netp::socket::listen_on( "tcp://0.0.0.0:22310",
[](NRP<netp::channel> const& ch) {
//once a new channel accepted, we add a echo handler which reply what it receives
ch->pipeline()->add_last(netp::make_ref<netp::handler::echo>());
});
int listenrt = std::get<0>(f_listen->get());
if(l