openframeworks/openFrameworks — pull request #3173 by totalgee (2014-08-26 14:46:34+00:00)
Title: ofxOsc: provide access to an ofxOscSender's local port

This was done in response to openframeworks/openFrameworks#2696. The idea was to give access to an ofxOscSender's local port. That way, an ofxOscReceiver could be created on the same port, and so all OSC communication could pass through a single port, simplifying client/server coding (a server can simply reply to clients at whatever port it receives their messages from).

A new method was added: `ofxOscSender:: getLocalPort()`. Internally, this uses a new method exposed in oscpack: `UdpSocket::LocalEndpointForConnectedRemoteEndpoint()`. The changes to oscpack were proposed by Ross Bencina, after discussing the issue with him. Note that some optimization was also done in `UdpSocket::LocalEndpointFor()`, to avoid disconnecting and reconnecting, in the case where the local endpoint is being requested for the (already-connected) target.

Typical usage (in an oF client using ofxOsc) would be something like this:

mSender.setup("localhost", serverPort);
int localPort = mSender.getLocalPort();
mRecv.setup(localPort);