THe following code is used to bind a socket to a port. The port specified is already bound to another UDP socket. I am finding that the socket gets bound to a random port if the port is already in use otherwise it gets bound to the specified port in the bind call. Is this the correct behaviour for ‘bind’. Using ASIO code on Android platform
asio::error_code errorCode;
mSocket.open(address.is_v6() ? asio::ip::udp::v6() : asio::ip::udp::v4(), errorCode);
if(!errorCode)
{
mSocket.set_option(asio::ip::udp::socket::reuse_address(true));
mSocket.bind(asio::ip::udp::endpoint(address, port), errorCode);
}
return errorCode;
Thanks
I suggest you check the error code on every operation, not just some of them. You will almost certainly find that the bind() has failed completely so a random bind is done automatically when you come to do a send or receive.