DatagramSocket multicast loopback setting


#1

Hi Juce foks,

I Was just wondering if you could possibly add a function to SocketHelpers (and DatagramSocket) that allows us to enable / disable multicast loopback?

It would only need to be simple, something like:

static bool multicastLoopback (int handle, bool loopback) noexcept
{
    int opt = (int)loopback;
    
    return setsockopt(handle,
                      IPPROTO_IP,
                      IP_MULTICAST_LOOP,
                      (char *)&opt,
                      sizeof(opt)) == 0;
}

and:

 /** Enable or disable multicast loopback
 @returns true if it succeeds.
 */
bool enableMulticastLoopback (bool loopback);

bool DatagramSocket::enableMulticastLoopback (bool loopback)
{
    if (! isBound || handle < 0)
        return false;

    return SocketHelpers::multicastLoopback(handle, false);
}

Would just make DatagramSocket that slight bit more versatile :slight_smile:


#2

Sure, will add that.


#3

Thanks!


#4

https://github.com/WeAreROLI/JUCE/commit/ea23ddd69e5451abd9f7976018adc8842d0587a7