Skip to content

Commit

Permalink
added broadcast and binding options
Browse files Browse the repository at this point in the history
  • Loading branch information
benkuper committed Jun 22, 2024
1 parent 669ac2c commit 4f98d0e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
15 changes: 15 additions & 0 deletions modules/juce_osc/juce_osc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
11 changes: 10 additions & 1 deletion modules/juce_osc/osc/juce_OSCReceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4f98d0e

Please sign in to comment.