3

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!

Christophe Roussy
  • 16,299
  • 4
  • 85
  • 85
Luuk D. Jansen
  • 4,402
  • 8
  • 47
  • 90
  • X32's OSC implementation is non-standard. It mostly follows OSC, but is broken in enough ways that it's unlikely you'll be able to use any off-the-shelf OSC client unless it's been modified for the X32. I think you'll find it easier to generate and parse messages yourself. – Brad Oct 11 '20 at 16:38
  • Thanks Brad. I have been working on it, and a difference I noticed using the X32_Command tool is (while I am off course not sure what is send with the tool) that the address seems to be send at the beginning of the request with the library and not with the tool, so you are probably right. Do you have any suggestion what to use for the communication? I am not really up to speed with low level communication protocols etc. – Luuk D. Jansen Oct 11 '20 at 18:24
  • 1
    Check out Wireshark so you can see what's happening in the packets being sent. Also, check out @Patrick-GillesMaillot excellent documentation: https://drive.google.com/file/d/1Snbwx3m6us6L1qeP1_pD6s8hbJpIpD0a/view – Brad Oct 11 '20 at 18:50
  • Thank you, I will do that. Yes, that is the document I found and where I realised the JAVA OSC does send more information. I will see if I can analyse the communication, thank you. – Luuk D. Jansen Oct 11 '20 at 19:07

0 Answers0