Hello. I’m trying to learn about OSC, through the oscP5 library. I have gotten it to work for me in limited circumstances (one Processing sketch sending, one other program receiving (Vuo, in my case).
In trying to understand how it works with many senders and receivers, I made a simple sketch that draws a big dot on the screen, sends its coordinates out over osc, and also listens for incoming messages. When it receives one, it draws a second smaller dot at the coordinates.
It works as expected on its own. I am trying to test multiple senders / receivers by running 3 instances of it under different names (that’s the only way I know of to do it). My understanding of OSC suggests that all three should be able to send and receive based on the address pattern I’m using, so my expected outcome is: if I put a dot on one of the windows, it should get a big dot, and all three should receive and place a small dot at the same coordinates. But I am finding that only one of the three ever receives the messages, and which one appears to be random (once I have started or stopped one of the others, sometimes none receives the messages.
The code I’m using is here:
// osc send & receive tester
import oscP5.*;
import netP5.*;
OscP5 oscP5;
NetAddress myRemoteLocation;
boolean recevied; // workaround
float rx, ry; //workaround
void setup() {
size(400,400);
frameRate(25);
background(40);
noStroke();
oscP5 = new OscP5(this,12000);
myRemoteLocation = new NetAddress("127.0.0.1",12000);
}
void draw() {
if (recevied) {
print("<<< "); // prefix console output with arrows for receiving
dot(rx,ry,30,100);
recevied = !recevied;
}
}
void dot (float x, float y, float d, int a) {
fill(255,a);
ellipseMode(CENTER);
ellipse(x*width,y*height,d,d);
println("dot size "+d+" at "+x+"-"+y);
}
void mousePressed() {
print(">>> "); // prefix console output with arrows for sending
OscMessage myMessage = new OscMessage("/test");
float x = float(mouseX)/width;
float y = float(mouseY)/height;
myMessage.add(x); /* add a float to the osc message */
myMessage.add(y); /* add a float to the osc message */
dot(x,y,50,100);
oscP5.send(myMessage, myRemoteLocation);
}
void oscEvent(OscMessage theOscMessage) {
if(theOscMessage.checkAddrPattern("/test")==true) {
if(theOscMessage.checkTypetag("ff")) {
float x = theOscMessage.get(0).floatValue();
float y = theOscMessage.get(1).floatValue();
recevied = true;
rx = x; ry = y;
return;
}
}
println("received unrecognized osc message");
}
I do notice an error message in the console for the instances I start after the first, and I’m sure it’s related to my problem:
### [2019/4/13 12:39:7] PROCESS @ OscP5 stopped.
### [2019/4/13 12:39:8] PROCESS @ UdpClient.openSocket udp socket initialized.
### [2019/4/13 12:39:9] ERROR @ UdpServer.start() IOException, couldnt create new DatagramSocket @ port 12000 java.net.BindException: Address already in use (Bind failed)
### [2019/4/13 12:39:9] INFO @ OscP5 is running. you (10.0.1.7) are listening @ port 12000
So, I expect my mistake is in how I am setting up the sending and listening ports on the oscP5 and netAddress objects, but I am basing my code on the examples, and I guess I don’t understand any further. Either I’m doing that stuff incorrectly or perhaps I can’t expect oscP5 to work this way.
Does anyone have any insights?
Thanks