Skip to content

Instantly share code, notes, and snippets.

@edouarda
Created February 13, 2018 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edouarda/ba33edcdd792a22f7f5e205bc1477041 to your computer and use it in GitHub Desktop.
Save edouarda/ba33edcdd792a22f7f5e205bc1477041 to your computer and use it in GitHub Desktop.
#include <boost/asio.hpp>
#include <iostream>
int main(int, char **)
{
boost::asio::io_context context;
auto ip = boost::asio::ip::address::from_string("127.0.0.1");
auto ep = boost::asio::ip::tcp::endpoint{ip, 666};
boost::asio::ip::tcp::acceptor acc{context, ep};
while (true)
{
boost::system::error_code ec;
auto s = acc.accept(ec);
if (ec)
{
std::cerr << ec.value() << ec.message() << std::endl;
break;
}
std::array<std::uint8_t, 1024> discard_buffer;
while (!ec)
{
auto l = s.read_some(boost::asio::buffer(discard_buffer), ec);
if (ec) break;
boost::asio::write(
s, boost::asio::const_buffer{discard_buffer.data(), l}, ec);
}
s.shutdown(boost::asio::socket_base::shutdown_both, ec);
s.close(ec);
}
acc.close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment