{Windows 7, MinGW 4.8, boost 1.55} I'm having some problems with UDP binds. I've a client that broadcasts datagrams for listeners listening on specific port and binds to a port itself if the listeners want to communicate something back. The port on which the client needs to bind is X and the servers are listening on Y. Problem: If I simulate a client-crash (eg., by causing segmentation fault by dereferencing a nullptr) after binding the UDP socket to the port, then once the client application is no longer running (no longer listed in Windows Task Manager) netstat -ano | find "X" still shows that someone is bound to port X and ip address of 0.0.0.0 (the client had specified the IP address as any address). The PID cannot be found in Windows Task Manager. However when I downloaded application TCPView I can see that a *<non-existent>* process is still bound to 50000. On starting the client (without making it crash this time) subsequently I get two behaviors: <1> On some machines the client is unable to bind to the socket again (although reuse_address option is set to true) and the error message is: An attempt was made to access a socket in a way forbidden by its access permissions. <2> On other machines the client binds successfully but the read handler is not called and the client does not receive any datagram on port X although the servers are unicasting to the client port X. Infact <2> is true even for launching multiple instances of the client on the same machine even if none of the clients were deliberately made to crash and exist as zombie processes. Only the 1st one gets datagrams. Here is how client socket is set up: if(!m_udpSocket.is_open()) { m_udpSocket.open(m_localEndpoint.protocol(), errorCode); //m_localEndpoint is address 0.0.0.0 and port X if(errorCode) { std::cerr << "Unable to open socket: " << errorCode.message() << std::endl; } else { m_udpSocket.set_option(boost::asio::socket_base::reuse_address(true), errorCode); if(errorCode) { std::cerr << "Reuse address option set failure. " << errorCode.message() << std::endl; } m_udpSocket.set_option(boost::asio::socket_base::broadcast(true), errorCode); if(errorCode) { std::cerr << "Socket cannot send broadcast. " << errorCode.message() << std::endl; } else { m_udpSocket.bind(m_localEndpoint, errorCode); if(errorCode) { std::cerr << "Socket cannot bind...!! " << errorCode.message() << std::endl; } } } } Can you explain why do I get <1> and <2> and what can I do to avoid them and make socket bind even if there is some other process bound to that socket? I need to support Windows, Linux and MAC -- View this message in context: http://boost.2283326.n4.nabble.com/UDP-bind-problems-tp4657731.html Sent from the Boost - Users mailing list archive at Nabble.com.
On 01/13/2014 11:10 AM, ustulation wrote:
<1> On some machines the client is unable to bind to the socket again (although reuse_address option is set to true) and the error message is: An attempt was made to access a socket in a way forbidden by its access permissions.
Is your endpoint is using the correct broadcast address? (obtained from ip::address_v4::broadcast())
I'm using:
m_remoteEndpointToSendDataTo
{boost::asio::ip::address::from_string("255.255.255.255"), Y};
//Y=some unsigned short
Is this wrong? But why would it affect binding and stuff anyway?
Note that the error message: "An attempt was made to access a socket
in a way forbidden by its access permissions" is during the binding
step.
On Mon, Jan 13, 2014 at 9:20 PM, Bjorn Reese [via Boost]
On 01/13/2014 11:10 AM, ustulation wrote:
<1> On some machines the client is unable to bind to the socket again (although reuse_address option is set to true) and the error message is: An attempt was made to access a socket in a way forbidden by its access permissions.
Is your endpoint is using the correct broadcast address? (obtained from ip::address_v4::broadcast())
_______________________________________________ Boost-users mailing list [hidden email] http://lists.boost.org/mailman/listinfo.cgi/boost-users
________________________________ If you reply to this email, your message will be added to the discussion below: http://boost.2283326.n4.nabble.com/UDP-bind-problems-tp4657731p4657761.html To unsubscribe from UDP bind problems, click here. NAML
-- ------------ spandan sharma -- View this message in context: http://boost.2283326.n4.nabble.com/UDP-bind-problems-tp4657731p4657773.html Sent from the Boost - Users mailing list archive at Nabble.com.
did you actually read the question (the 1st post in the forum under
this topic)? I have written the code explicitly there:
if(!m_udpSocket.is_open())
{
m_udpSocket.open(m_localEndpoint.protocol(), errorCode);
//m_localEndpoint is address 0.0.0.0 and port X
if(errorCode)
{
std::cerr << "Unable to open socket: " << errorCode.message()
<< std::endl;
}
else
{
m_udpSocket.set_option(boost::asio::socket_base::reuse_address(true),
errorCode);
if(errorCode)
{
std::cerr << "Reuse address option set failure. " <<
errorCode.message() << std::endl;
}
m_udpSocket.set_option(boost::asio::socket_base::broadcast(true),
errorCode);
if(errorCode)
{
std::cerr << "Socket cannot send broadcast. " <<
errorCode.message() << std::endl;
}
else
{
m_udpSocket.bind(m_localEndpoint, errorCode);
if(errorCode)
{
std::cerr << "Socket cannot bind...!! " <<
errorCode.message() << std::endl;
}
}
}
}
Do you mean there's anything wrong with this?
On Mon, Jan 13, 2014 at 11:42 PM, Cliff Green-3 [via Boost]
{boost::asio::ip::address::from_string("255.255.255.255"), Y}; //Y=some unsigned short Is this wrong? But why would it affect binding and stuff anyway?
You must set the broadcast socket option to send to a broadcast address (check out the Asio socket options).
Cliff
_______________________________________________ Boost-users mailing list [hidden email] http://lists.boost.org/mailman/listinfo.cgi/boost-users
________________________________ If you reply to this email, your message will be added to the discussion below: http://boost.2283326.n4.nabble.com/UDP-bind-problems-tp4657731p4657774.html To unsubscribe from UDP bind problems, click here. NAML
-- ------------ spandan sharma -- View this message in context: http://boost.2283326.n4.nabble.com/UDP-bind-problems-tp4657731p4657776.html Sent from the Boost - Users mailing list archive at Nabble.com.
participants (3)
-
Bjorn Reese
-
Cliff Green
-
ustulation