Skip to content

Commit 4b5632a

Browse files
authored
add setup argument to listen on specific ip (#7574)
1 parent da1dc6b commit 4b5632a

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

addons/ofxOsc/src/ofxOscReceiver.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ ofxOscReceiver& ofxOscReceiver::copy(const ofxOscReceiver &other){
2828
}
2929

3030
//--------------------------------------------------------------
31-
bool ofxOscReceiver::setup(int port){
31+
bool ofxOscReceiver::setup(int port, std::string host) {
3232
if(listenSocket){ // already running
3333
stop();
3434
}
3535
settings.port = port;
36+
settings.host = host;
3637
return start();
3738
}
3839

@@ -62,7 +63,7 @@ bool ofxOscReceiver::start() {
6263
// create socket
6364
osc::UdpListeningReceiveSocket *socket = nullptr;
6465
try{
65-
osc::IpEndpointName name(osc::IpEndpointName::ANY_ADDRESS, settings.port);
66+
osc::IpEndpointName name(settings.host.c_str(), settings.port);
6667
socket = new osc::UdpListeningReceiveSocket(name, this, settings.reuse);
6768
auto deleter = [](osc::UdpListeningReceiveSocket*socket){
6869
// tell the socket to shutdown

addons/ofxOsc/src/ofxOscReceiver.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
/// \struct ofxOscSenderSettings
1414
/// \brief OSC message sender settings
1515
struct ofxOscReceiverSettings {
16-
int port = 0; ///< port to listen on
17-
bool reuse = true; ///< should the port be reused by other receivers?
18-
bool start = true; ///< start listening after setup?
16+
int port = 0; ///< port to listen on
17+
std::string host = "0.0.0.0"; ///< host to listen on
18+
bool reuse = true; ///< should the port be reused by other receivers?
19+
bool start = true; ///< start listening after setup?
1920
};
2021

2122
/// \class ofxOscReceiver
@@ -30,14 +31,14 @@ class ofxOscReceiver : public osc::OscPacketListener {
3031
/// for operator= and copy constructor
3132
ofxOscReceiver& copy(const ofxOscReceiver &other);
3233

33-
/// set up the receiver with the port to listen for messages on
34+
/// set up the receiver with the port (and specific host/ip) to listen for messages on
3435
/// and start listening
3536
///
3637
/// multiple receivers can share the same port if port reuse is
3738
/// enabled (true by default)
3839
///
3940
/// \return true if listening started
40-
bool setup(int port);
41+
bool setup(int port, std::string host = "0.0.0.0");
4142

4243
/// set up the receiver with the given settings
4344
///

0 commit comments

Comments
 (0)