Advertisement
bueddl

Untitled

Sep 26th, 2015
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1.  
  2. void my_connect_handler4(net::socket::tcp::child4 &sock)
  3. {
  4.     std::cout << "New client connected (IPv4)" << std::endl;
  5. }
  6.  
  7. void my_connect_handler6(net::socket::tcp::child6 &sock)
  8. {
  9.     std::cout << "New client connected (IPv6)" << std::endl;
  10. }
  11.  
  12. void my_receive_handler4(net::socket::tcp::child4 &sock, net::socket::buffer buffer)
  13. {
  14.     std::cout << "New data (IPv4) [" << buffer.size() << "]: " << *buffer << std::endl;
  15. }
  16.  
  17. void my_receive_handler6(net::socket::tcp::child6 &sock, net::socket::buffer buffer)
  18. {
  19.     std::cout << "New data (IPv6) [" << buffer.size() << "]: " << *buffer << std::endl;
  20. }
  21.  
  22. int application::run()
  23. {
  24.     net::connection_pool pool;
  25.     pool.listen(8080);
  26.  
  27.     pool.on_connect<net::socket::endpoint>() += my_connect_handler4;
  28.     pool.on_connect<net::socket::endpoint6>() += my_connect_handler6;
  29.  
  30.     pool.on_receive<net::socket::endpoint>() += my_receive_handler4;
  31.     pool.on_receive<net::socket::endpoint6>() += my_receive_handler6;
  32.  
  33.     pool.start_accept();
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement