#include #include #include using boost::asio::io_service; using boost::asio::ip::tcp; using boost::lexical_cast; using boost::system::error_code; using boost::system::system_error; using std::cerr; int main(int argc, char *argv[]) { try { short port = 1492; if (argc > 1) port = lexical_cast(argv[1]); io_service io_svc; tcp::endpoint ep(tcp::v4(), port); cerr << "Creating acceptor ...\n"; tcp::acceptor acc(io_svc, ep); for (;;) { cerr << "Creating stream ...\n"; tcp::iostream stream; cerr << "Calling accept ...\n"; acc.accept(*stream.rdbuf()); cerr << "Reading from socket ...\n"; std::string buf; while (std::getline(stream, buf)) cerr << "READ: " << buf.data() << "\n"; } } catch (system_error const & e) { cerr << e.what() << "\n"; } }