Unbinding the UDP Port


I have an object class that declares and sets up an ofxOscReceiver object with a predefined port.

I need to be able to delete and create objetcs of this class dinamicaly (with keyboard interaction).

When I clear the objects I get no error message, but when I create a new one I get this error:

terminate called after throwing an instance of ‘std::runtime_error’
what(): unable to bind udp socket

This means that it doesn’t allow me to do:


more then once on the app.

How can I unbind the UDP port when deleting my object ?



I’m not sure this is 100% correct, but this is what I’ve done in the past to reroute OSC.
I added this function to ofxOscReceiver to stop its thread + release its socket.

void ofxOscReceiver::closeSocket()  
	delete listen_socket;  
	delete thread;  

I think you could just add this to the destructor as well + it would work.
With this, though, I’m using pointers with ofxOscReceiver like this:

ofxOscReceiver * receiver;  
void reroute(int _port){  
	port = _port;  
	receiver = new ofxOscReceiver();  
	receiver->setup( port );  

that works for me. There’s also this AsynchronousBreak() function on UdpListeningReceiveSocket, but I’m not positive if you need to use that as well.

Thanks for the help.

I switched to using the ofxUDPmanager addon and it has a Close() method that works well too.

Thanks again for the help.



there’s been an update to ofxOsc, it should be included in oF 0.61, but in the meantime you can get the latest using subversion:

svn co [http://damian.dreamhosters.com/svn/public/ofxOsc/latest/](http://damian.dreamhosters.com/svn/public/ofxOsc/latest/)