From 4f98d0ec2f6ad092d3d5a3a3036971f7308a48a9 Mon Sep 17 00:00:00 2001 From: Ben Kuper Date: Sat, 22 Jun 2024 20:12:10 +0200 Subject: [PATCH] added broadcast and binding options --- modules/juce_osc/juce_osc.h | 15 +++++++++++++++ modules/juce_osc/osc/juce_OSCReceiver.cpp | 11 ++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/modules/juce_osc/juce_osc.h b/modules/juce_osc/juce_osc.h index 19eeb7665cbc..28e5326b0969 100644 --- a/modules/juce_osc/juce_osc.h +++ b/modules/juce_osc/juce_osc.h @@ -68,6 +68,21 @@ #ifndef JUCE_ALLOW_SPECIAL_CHARS_IN_ADDRESS #define JUCE_ALLOW_SPECIAL_CHARS_IN_ADDRESS 0 #endif + +/** Config: JUCE_ENABLE_BROADCAST_BY_DEFAULT + Automatically enables broadcast on bound port in OSCReceiver +*/ +#ifndef JUCE_ENABLE_BROADCAST_BY_DEFAULT +#define JUCE_ENABLE_BROADCAST_BY_DEFAULT 0 +#endif + +/** Config: JUCE_EXCLUSIVE_BINDING_BY_DEFAULT + If enabled, this will make the binding of this port exclusive, so no other process can bind it. +*/ +#ifndef JUCE_EXCLUSIVE_BINDING_BY_DEFAULT +#define JUCE_EXCLUSIVE_BINDING_BY_DEFAULT 0 +#endif + /** Config: JUCE_IP_AND_PORT_DETECTION If enabled, this will add remoteIP and remotePort variables to osc packets, corresponding to the sender's ip and port when receiving messages. */ diff --git a/modules/juce_osc/osc/juce_OSCReceiver.cpp b/modules/juce_osc/osc/juce_OSCReceiver.cpp index f0510ba5d3c4..d6959dd2170b 100644 --- a/modules/juce_osc/osc/juce_OSCReceiver.cpp +++ b/modules/juce_osc/osc/juce_OSCReceiver.cpp @@ -354,7 +354,16 @@ struct OSCReceiver::Pimpl : private Thread, if (! disconnect()) return false; - socket.setOwned (new DatagramSocket (false)); +#if JUCE_ENABLE_BROADCAST_BY_DEFAULT + DatagramSocket* datagram = new DatagramSocket(true); +#else + DatagramSocket* datagram = new DatagramSocket(false); +#endif + socket.setOwned(datagram); + +#if JUCE_EXCLUSIVE_BINDING_BY_DEFAULT + socket->setEnablePortReuse(false); +#endif if (! socket->bindToPort (portNumber)) return false;