Strengthen UDP socket problem by unix-bind: address is already in use

First of all, I know that in one topic there are several other threads, but I could not find anything in those that can help me, so I will try to be very specific with my situation.

I installed a simple UDP Client / UDP Server pair, which is responsible for transferring data between several parallel simulations. That is, each instance of the simulator works in a separate stream and sends data to the UDP socket. In the main thread, the server is running and routing messages between simulations.

(for this problem) important parts of the server code are as follows:

UDPServer::UDPServer(boost::asio::io_service &m_io_service) :
   m_socket(m_io_service, udp::endpoint(udp::v4(), PORT_NUMBER)),
   m_endpoint(boost::asio::ip::address::from_string("127.0.0.1"), PORT_NUMBER)
{
   this->start_receive();
};

void UDPServer::start_receive() {

   // Set SO_REUSABLE to true
   boost::asio::socket_base::reuse_address option(true);
   this->m_socket.set_option(option);

   // Specify what happens when a message is received (it should call the handle_receive function)
   this->m_socket.async_receive_from(   boost::asio::buffer(this->recv_buffer),
                                        this->m_endpoint,
                                        boost::bind(&UDPServer::handle_receive, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));

};

This works fine on my windows workstation.

; linux, node. , ,

bind: address already in use

1024 , . , , reuse_address, , .

+4
2

SO_REUSEADDR :

UDPServer::UDPServer(boost::asio::io_service &m_io_service) :
   m_socket(m_io_service, udp::v4()),
   m_endpoint()
{
   boost::asio::socket_base::reuse_address option(true);
   this->m_socket.set_option(option);
   this->m_socket.bind(udp::endpoint(udp::v4(), PORT_NUMBER));
   this->start_receive();
}

, endpoint, - , . , , .

, m_endpoint, out async_receive_from .

+2

Linux, , .

netstat -antup | grep 1024

" ", - . , , . , , .

0

All Articles