Using JavaOsc to get meter readings from a Behringer X32

323 views Asked by At

I am trying to work with JavaOsc but I am having difficulties establishing a connection. My test code is below, but it does not matter what IP address port I put in, it appears to connect (which is not correct) and there is no response I am receiving. So I am doing something wrong, but find it hard to find documentation.

    final static private int port = 10023;
    final static private String ipAddess = "192.168.1.78";

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while(true) {
            OSCPortOut sender = null;
            OSCPortIn receiver = null;
            try {
                //receiver = new OSCPortIn(10023);
                OSCMessageListener msgListener = new OSCMessageListener() {
                    @Override
                    public void acceptMessage(OSCMessageEvent oscMessageEvent) {
                        System.out.println("Message received A! " + oscMessageEvent.toString());
                    }
                };

                OSCPacketListener listener = new OSCPacketListener() {
                    @Override
                    public void handlePacket(OSCPacketEvent oscPacketEvent) {
                        System.out.println("Package received A! " + oscPacketEvent.toString());
                    }

                    @Override
                    public void handleBadData(OSCBadDataEvent oscBadDataEvent) {
                        System.out.println("Package BAD received B!");
                    }

                    public void acceptMessage(java.util.Date time, OSCMessage message) {
                        System.out.println("Message received!");
                    }
                };

                MessageSelector selector = new MessageSelector() {
                    @Override
                    public boolean isInfoRequired() {
                        System.out.println("Info required call");
                        return false;
                    }

                    @Override
                    public boolean matches(OSCMessageEvent oscMessageEvent) {
                        System.out.println("Message match?? " + oscMessageEvent.toString());
                        return false;
                    }
                };
                
                receiver = new OSCPortInBuilder().addPacketListener(listener).addMessageListener(selector, msgListener).setLocalPort(port).setRemotePort(port).build();
                receiver.connect();
                receiver.startListening();

                sender = new OSCPortOut(InetAddress.getByName(ipAddess), port);
                sender.connect();
                System.out.println("Remote address: " + sender.getRemoteAddress() + " local: " + sender.getLocalAddress());
                List<String> vars = new ArrayList<String>();
                vars.add("/info");
                OSCMessage msg = new OSCMessage("/msgAddress", vars);

                System.out.println("Is connected: " + sender.isConnected());
                sender.send(msg);     
                System.out.println("Msg info: " + msg.getInfo() + " - " + msg.getAddress());

                System.out.println("Deamon: " + receiver.isDaemonListener() + " is listening " + receiver.isListening() + " is connected " + receiver.isConnected());

                System.out.println("Please type 'q' to stop.");
                if(scanner.nextLine().equalsIgnoreCase("q")) break;

            } catch (Exception e) {
                System.out.println("Error: " + e.getMessage());
                e.printStackTrace(System.out);
            } finally {
                try {
                    if (sender != null) sender.close();
                    if (receiver != null) receiver.close();
                } catch (IOException e){
                    System.out.println("Problem closing: " + e.getMessage());
                }
            }
        }
        System.out.println("Finished.");

The response is:

Info required
Remote address: /192.168.1.78:10023 local: /0.0.0.0:0
Is connected: true
Msg info: null - /msgAddress
Deamon: true is listening true is connected true
Please type 'q' to stop.

I also tried to contact the local receiver (using 127.0.0.1) but that didn't work either. Any suggestions would be really appreciated!

0

There are 0 answers