Hey, sorry to pull this up again but things are not clear to me.

i want to setup OSC communication between Max and Bela.
in Max I´m using the node.script obj and basically copy/pasted the osc.js example code from bela, except replacing the remoteIP adress with one of the IPs of the BELA board, showing in Network Preferences.
two devices are showing up with
192.168.6.1
192.168.7.1

alt text

https://learn.bela.io/using-bela/technical-explainers/ip-addresses/
this post says " IP address of the board will end with 2. " so thats not uptodate?

on the BELA runs \example Communication/OSC/render.cpp
except that i replaced the remoteIP with the one of my host computer.

BELA console prints:

alt text

    D300 this post says " IP address of the board will end with 2. " so thats not uptodate?

    it is. Each USB port creates a small virtual network with 2 devices on it: your computer and Bela. Bela is assigned a .2 address and you computer is assigned a .1 address. So your computer shows the .1 address but to connect to Bela you have to use the .2 address (or you can use bela.local to avoid having to worry about it). Conversely, to connect form Bela to the host computer you should use the .1 address.

    D300 BELA console prints:

    In the setup() function, that example sends /osc-setup to the server

    	oscSender.newMessage("/osc-setup").send();

    and in on_receive(), it waits for a reply /osc-setup-reply

    if(msg->match("/osc-setup-reply"))
    		handshakeReceived = true;

    If you didn't implement this in your Max patch, you should remove all of:

    	// the following code sends an OSC message to address /osc-setup
    	// then waits 1 second for a reply on /osc-setup-reply
    	oscSender.newMessage("/osc-setup").send();
    	int count = 0;
    	int timeoutCount = 10;
    	printf("Waiting for handshake ....\n");
    	while(!handshakeReceived && ++count != timeoutCount)
    	{
    		usleep(100000);
    	}
    	if (handshakeReceived) {
    		printf("handshake received!\n");
    	} else {
    		printf("timeout! : did you start the node server? `node /root/Bela/resources/osc/osc.js\n");
    		return false;
    	}

    Is your max patch receiving the /osc-setup message at all? Make sure you have modified remoteIp to be

    const char* remoteIp = "192.168.7.1"; // or .6.1
    • D300 replied to this.

      giuliomoro

      i think I know what the problem is.
      somehow the setup function is not called at the beginning when i start the process but only when i stop the process..

      bool setup(BelaContext *context, void *userData)
      {
      	rt_printf("setup function is executed?");
          
          oscReceiver.setup(localPort, on_receive);
      	oscSender.setup(remotePort, remoteIp);
      
      	// the following code sends an OSC message to address /osc-setup
      	// then waits 1 second for a reply on /osc-setup-reply
      	
      	printf("this function is not called");
      	oscSender.newMessage("/osc-setup").send();
      
      	return true;
      }

      consequently the port and the callback are not setup and thus i´m not getting messages.
      i tried other examples as the "print example" or the "sinetone" and in that examples the setup() was evoked before the render() and cleanup()...

      oscReceiver.setup(localPort, on_receive);
      alt text

      and this is the OSC side of max, as said just took your osc.js and wrapped it into node.script max obj

        D300 i think I know what the problem is.
        somehow the setup function is not called at the beginning when i start the process but only when i stop the process..

        That's not true. setup() is always called when the program starts. You need a \n (newline) character at the end of each print statement for it to be printed there and then, otherwise it may be cached until a newline comes in or the program terminates. Also, replace rt_printf() with printf(). The issue you are having may be that the localIp as specified only accepts connections to 127.0.0.1 but the connection from the board will go to 192.168.7.1. If you are on a safe network, you can specify 0.0.0.0 to accept connections on any IP.

        • D300 replied to this.

          giuliomoro that was it.. 0.0.0.0 aka. "wildcard" never played that one before haha
          thanks alot !

          but, the bela prints:
          From 192.168.7.1:35613
          why that port?

          and regarding 0.0.0.0 :
          you say "localIp" as specified, can I also change the network settings in a way that localhost works?
          if I understand this stackoverflow post right, then there is no way with localhost on another machine...

          (https://stackoverflow.com/questions/39314086/what-does-it-mean-to-bind-a-socket-to-any-address-other-than-localhost)

          "If you bind a socket for receiving data to a specific address you can only receive data sent to this specific IP address. For example, if you bind to 127.0.0.1 you will be able to receive data from your own system but not from some other system on the local network, because they cannot send data to your 127.0.0.1: for one any data to 127.0.0.1 will be sent to their own 127.0.0.1 and second your 127.0.0.1 is an address on your internal loopback interface which is not reachable from outside."

            D300 From 192.168.7.1:35613
            why that port?

            Why not? The host opens port 7563 to receive communications. Once the connection is established and it knows what port to send to , it opens a different port (which is irrelevant in this case) to send data, this is 35613 in this case but it will change every time.

            D300 and regarding 0.0.0.0 :
            you say "localIp" as specified, can I also change the network settings in a way that localhost works?

            What they say there is that localhost or 127.0.0.1 only works from a given machine to address itself.: any machine will find itself at localhost or 127.0.0.1. So for instance you cannot connect from Bela to the host using localhost, because it will address the request to itself. This said, if you want to be able to connect to Max from both Bela and from a program on the same machine that Max runs on, then 0.0.0.0 is fine: it accepts connections from any IP address, including from the same machine it's running on.