Hi my code works properly on windows but on linux the reconnect feature doesn't work,it throws an exception with WSAEADDRINUSE
value.
pClientSocket = new tcp::socket(*pIO_context, tcp::endpoint(boost::asio::ip::make_address(127.0.0.1, 50001));
First time it works on both Windows and Linux, but when i close the socket and try to connect again, i am getting an exception as described above only on linux OS.
Here is the close socket code.
boost::system::error_code ec;
pClientSocket->shutdown( boost::asio::socket_base::shutdown_type::shutdown_receive, ec);
pClientSocket->close(eCode);
delete pClientSocket;
pClientSocket= nullptr;
CodePudding user response:
Try using the reuse option:
boost::asio::socket_base::reuse_address option(true);
socket.set_option(option);