hoijui / JavaOSC

OSC content format/"protocol" library for JVM languages

Home Page:http://www.illposed.com/software/javaosc.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pass sender's InetSocketAddress to OSCListener

showlabor opened this issue · comments

AFAICT, currently it's impossible to tell where a OSCMessage is coming from in a OSCLIstener. That information is vital though for many possible applications. (BTW, that made me switch from JavaOSC to using NetUtil mostly some time ago.)
E.g. Behringer X Air mixers respond to a broadcast message such that a control app is able to find a mixer on the network .Moreover, if you have more than one of those mixers on the net it is important to know the source of a message send to the control app.

I'd very much like to move from

public interface OSCListener {
	void acceptMessage(Date time, OSCMessage message);
}

to

public interface OSCListener {
	void acceptMessage(Date time, OSCMessage message, InetSocketAddress sender);
}

But that would probably break too much legacy code. So maybe a second kind of Listeners could be introduced.

What do you think?

Kind regards,
Felix

ahh yep, that makes sense indeed, thank you! :-)
i will have a look at it...
But first though i have is looking at these code snippets, is that i clearly made a design fault-pas in the beginning already, by not using the scheme (which is standard in Java) of using a single event object, but passing multiple objects as event arguments, which is a bad idea for exactly these kinds of scenarios. ;-)
so... best would be, to change that, and thus play safe for the future at least, as we have to break the interface anyway. i think introducing a new listener just to prevent breaking the API is not a good idea. it leads to lots of confusion for people that don't see the history of the code.

please see this commit:
cd36c67
it is only on the develop branch so far, and can thus easily be modified.
what do you think about this solution?

now superseeded by b171e65.
To get the receiving address, you would do this:

public interface OSCMessageListener {

	void acceptMessage(OSCMessageEvent event) {

		OSCPortIn portIn = (OSCPortIn) event.getSource();
		InetSocketAddress receivingAddress = (InetSocketAddress) portIn.getLocalAddress();
	}
}

or with a lover level listener (new):

public class MyListener implements OSCPacketListener {
	public void handlePacket(OSCPacketEvent event) {

		OSCPortIn portIn = (OSCPortIn) event.getSource();
		InetSocketAddress receivingAddress = (InetSocketAddress) portIn.getLocalAddress();
	}
	public void handleBadData(OSCBadDataEvent event) { ... }
}

It wil be in the next release, and can until then can be tested in the snaphost (com.illposed.osc:javaosc-core:0.5-SNAPSHOT).