-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathecho_client_example.cc
More file actions
40 lines (36 loc) · 877 Bytes
/
echo_client_example.cc
File metadata and controls
40 lines (36 loc) · 877 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#define ENABLE_ELG_LOG
#include <elog/logger.h>
#include <netpoll/core.h>
using namespace elog;
std::string input()
{
std::cout << "please enter you message:";
std::string ret;
std::cin >> ret;
return ret;
}
struct client
{
NETPOLL_TCP_CONNECTION(conn)
{
if (conn->connected()) { conn->send(input()); }
}
NETPOLL_TCP_MESSAGE(conn, buffer)
{
ELG_INFO("msg received:{}", buffer->readAll());
conn->send(input());
}
};
int main()
{
elog::GlobalConfig::Get().setLevel(elog::kTrace);
auto loop = netpoll::NewEventLoop(1);
auto dialer = netpoll::tcp::Dialer::New({"127.0.0.1", 6666});
#if __cplusplus >= 201703L || (_MSC_VER && _MSVC_LANG >= 201703L)
dialer.bind<client>();
#else
netpoll::tcp::Dialer::Register<client>();
dialer.bindOnConnection<client>().bindOnMessage<client>();
#endif
loop.serve(dialer);
}