#include #include "boost/asio.hpp" using namespace boost::asio; int main(int argc, const char* argv[]) { io_service io_service; ip::tcp::socket::endpoint_type endpoint( ip::address_v4::from_string("127.0.0.1"), 9999); ip::tcp::socket tcp_socket(io_service); tcp_socket.async_connect(endpoint, [](const boost::system::error_code& ec) { if (ec.value() != boost::asio::error::connection_refused) { std::cout << "Expected error code " << boost::asio::error::connection_refused << " but got " << ec.value() << std::endl; } else { std::cout << "got error code " << ec.value() << std::endl; } }); io_service.run(); return 0; }