| 20 | const int max_length = 1024; |
| 21 | |
| 22 | void session(tcp::socket sock) |
| 23 | { |
| 24 | try |
| 25 | { |
| 26 | for (;;) |
| 27 | { |
| 28 | char data[max_length]; |
| 29 | |
| 30 | boost::system::error_code error; |
| 31 | size_t length = sock.read_some(boost::asio::buffer(data), error); |
| 32 | if (error == boost::asio::stream_errc::eof) |
| 33 | break; // Connection closed cleanly by peer. |
| 34 | else if (error) |
| 35 | throw boost::system::system_error(error); // Some other error. |
| 36 | |
| 37 | boost::asio::write(sock, boost::asio::buffer(data, length)); |
| 38 | } |
| 39 | } |
| 40 | catch (std::exception& e) |
| 41 | { |
| 42 | std::cerr << "Exception in thread: " << e.what() << "\n"; |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | void server(boost::asio::io_context& io_context, unsigned short port) |
| 47 | { |