From 4b5632acfc4ad42639b29a79f2f63d935925a565 Mon Sep 17 00:00:00 2001 From: 2bit Date: Sat, 22 Jul 2023 02:20:24 +0900 Subject: [PATCH] add setup argument to listen on specific ip (#7574) --- addons/ofxOsc/src/ofxOscReceiver.cpp | 5 +++-- addons/ofxOsc/src/ofxOscReceiver.h | 11 ++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/addons/ofxOsc/src/ofxOscReceiver.cpp b/addons/ofxOsc/src/ofxOscReceiver.cpp index 3c0d73160e0..fbf291605f0 100644 --- a/addons/ofxOsc/src/ofxOscReceiver.cpp +++ b/addons/ofxOsc/src/ofxOscReceiver.cpp @@ -28,11 +28,12 @@ ofxOscReceiver& ofxOscReceiver::copy(const ofxOscReceiver &other){ } //-------------------------------------------------------------- -bool ofxOscReceiver::setup(int port){ +bool ofxOscReceiver::setup(int port, std::string host) { if(listenSocket){ // already running stop(); } settings.port = port; + settings.host = host; return start(); } @@ -62,7 +63,7 @@ bool ofxOscReceiver::start() { // create socket osc::UdpListeningReceiveSocket *socket = nullptr; try{ - osc::IpEndpointName name(osc::IpEndpointName::ANY_ADDRESS, settings.port); + osc::IpEndpointName name(settings.host.c_str(), settings.port); socket = new osc::UdpListeningReceiveSocket(name, this, settings.reuse); auto deleter = [](osc::UdpListeningReceiveSocket*socket){ // tell the socket to shutdown diff --git a/addons/ofxOsc/src/ofxOscReceiver.h b/addons/ofxOsc/src/ofxOscReceiver.h index 329b73ba98b..83c3ff8d619 100644 --- a/addons/ofxOsc/src/ofxOscReceiver.h +++ b/addons/ofxOsc/src/ofxOscReceiver.h @@ -13,9 +13,10 @@ /// \struct ofxOscSenderSettings /// \brief OSC message sender settings struct ofxOscReceiverSettings { - int port = 0; ///< port to listen on - bool reuse = true; ///< should the port be reused by other receivers? - bool start = true; ///< start listening after setup? + int port = 0; ///< port to listen on + std::string host = "0.0.0.0"; ///< host to listen on + bool reuse = true; ///< should the port be reused by other receivers? + bool start = true; ///< start listening after setup? }; /// \class ofxOscReceiver @@ -30,14 +31,14 @@ class ofxOscReceiver : public osc::OscPacketListener { /// for operator= and copy constructor ofxOscReceiver& copy(const ofxOscReceiver &other); - /// set up the receiver with the port to listen for messages on + /// set up the receiver with the port (and specific host/ip) to listen for messages on /// and start listening /// /// multiple receivers can share the same port if port reuse is /// enabled (true by default) /// /// \return true if listening started - bool setup(int port); + bool setup(int port, std::string host = "0.0.0.0"); /// set up the receiver with the given settings ///