From ea23ddd69e5451abd9f7976018adc8842d0587a7 Mon Sep 17 00:00:00 2001 From: ed Date: Thu, 14 Dec 2017 15:15:03 +0000 Subject: [PATCH] Added a method to DatagramSocket to set whether multicast loopback should be enabled --- modules/juce_core/network/juce_Socket.cpp | 8 ++++++++ modules/juce_core/network/juce_Socket.h | 10 ++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/modules/juce_core/network/juce_Socket.cpp b/modules/juce_core/network/juce_Socket.cpp index 1fb520b938..4ffcf49f90 100644 --- a/modules/juce_core/network/juce_Socket.cpp +++ b/modules/juce_core/network/juce_Socket.cpp @@ -741,6 +741,14 @@ bool DatagramSocket::leaveMulticast (const String& multicastIPAddress) return SocketHelpers::multicast (handle, multicastIPAddress, lastBindAddress, false); } +bool DatagramSocket::setMulticastLoopbackEnabled (bool enable) +{ + if (! isBound || handle < 0) + return false; + + return SocketHelpers::setOption (handle, IPPROTO_IP, IP_MULTICAST_LOOP, enable); +} + bool DatagramSocket::setEnablePortReuse (bool enabled) { #if JUCE_ANDROID diff --git a/modules/juce_core/network/juce_Socket.h b/modules/juce_core/network/juce_Socket.h index 1b97325adb..fe689b4fe8 100644 --- a/modules/juce_core/network/juce_Socket.h +++ b/modules/juce_core/network/juce_Socket.h @@ -315,18 +315,24 @@ public: void shutdown(); //============================================================================== - /** Join a multicast group + /** Join a multicast group. @returns true if it succeeds. */ bool joinMulticast (const String& multicastIPAddress); - /** Leave a multicast group + /** Leave a multicast group. @returns true if it succeeds. */ bool leaveMulticast (const String& multicastIPAddress); + /** Enables or disables multicast loopback. + + @returns true if it succeeds. + */ + bool setMulticastLoopbackEnabled (bool enableLoopback); + //============================================================================== /** Allow other applications to re-use the port.