We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSound,  Music Libraries › Routing OSC to multiple ports
Page Index Toggle Pages: 1
Routing OSC to multiple ports (Read 969 times)
Routing OSC to multiple ports
Jun 14th, 2009, 2:25pm
 
Hallo!

just joined the forum and 1 week processing user years old....
Using the OSCp5 library I've managed in sending OSC messages to one port.
I'm trying to route the same message to two different ports at the same time.
Does anybody know how?
actually I'd have another Q but my knowledge of processing is still very basic, it's kind of the evolution of the Q above:

is there a way to get an icoming osc message from 1 port (let's say 8000) and  transforn  that same osc msg in another OSC msg and send it to another port (let's say 9000)?
the logical translation of this would be something like:
if OSC msg "x" arrives from port 8000, then send OSC msg "y" to port 9000.

thanks you loads
Re: Routing OSC to multiple ports
Reply #1 - Jun 14th, 2009, 5:50pm
 
hi,
this might help, for details take a look at the comments in the code

Code:


import oscP5.*;
import netP5.*;

OscP5 oscP5;
NetAddress myRemoteAddress;

void setup() {
 size(400,400);
 frameRate(25);
 // start oscP5, listen for incoming messages at port 8000
 oscP5 = new OscP5(this,8000);
 
 // a remote address.
 // incoming messages will be forwarded to this address
 myRemoteAddress = new NetAddress("127.0.0.1",9000);
}


void draw() {
 background(0);  
}

// for testing purposes.
// press key 1 to send a message to port 8000 on your local machine

void keyPressed() {
 OscMessage myMessage;
 switch(key) {
   case('1'):
   myMessage = new OscMessage("/test");
   myMessage.add(1);
   NetAddress n = new NetAddress("127.0.0.1",8000);
   oscP5.send(myMessage, n);
   println("sending a message to "+n);
   break;
 }
}



void oscEvent(OscMessage theOscMessage) {
   // oscP5 is listening at port 8000 (see setup).
   // incoming messages are sent to the oscEvent method.
   println("received a message.");
   
   // forwarding the same message to another address/port:

   // if you need to change the address pattern of the message
   // you just received, use:
   theOscMessage.setAddrPattern("/some/other/addressPattern");

   // now forward the message by sending it to your remote address.
   oscP5.send(theOscMessage, myRemoteAddress);
   println("forwarding message to "+myRemoteAddress);
}

Re: Routing OSC to multiple ports
Reply #2 - Jun 14th, 2009, 7:54pm
 
thank you very much!


this is really interesting and useful! may I ask you where is this sketch from? more sketches concerning osc and routing like this one will help me a lot.
this one isn't within the oscp5 library examples, is it?
Page Index Toggle Pages: 1