At the first launch, the bandage passes successfully, when the program is restarted, it screams that the address is already in use, the address is released after a couple of minutes.
If you do not call shutdown and close, then everything will be successful every time (when the program is restarted, of course)
boost::asio::io_service _ioService; boost::asio::ip::tcp::socket _socket(_ioService); boost::system::error_code err; _socket.open(boost::asio::ip::tcp::v4(), err); _socket.bind(boost::asio::ip::tcp::endpoint(boost::asio::ip::address_v4::from_string("127.0.0.1"), 1250), err); if (err.value()) { cout << err.value() << endl; cout << err.message() << endl; } _socket.connect(boost::asio::ip::tcp::endpoint(boost::asio::ip::address_v4::from_string("127.0.0.1"), 1500), err); //_socket.shutdown(_socket.shutdown_both); //_socket.close(err);
SO_REUSEADDR. If you can use socket options in boost, this will be the solution to your question. - Max ZS