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 & HelpOther Libraries › OSCP5 string problem
Page Index Toggle Pages: 1
OSCP5 string problem (Read 371 times)
OSCP5 string problem
May 21st, 2008, 3:49pm
 
Hello,

i have a problem with oscP5. I try to send an array of messages form one processing programm to a other one. For most characters this is no problem but incase of the characters "äöü" there arrives just a ?.
Does someone know how to handle this problem?
Thank s a lot



import oscP5.*;
import netP5.*;
OscP5 oscP5;
NetAddress myRemoteLocation;

void setup() {
 size(400,400);
 oscP5 = new OscP5(this,12000);
 myRemoteLocation = new NetAddress("127.0.0.1",12000);
}

void draw() {
 background(0);  
}

void mousePressed() {
 OscMessage myMessage = new OscMessage("hallo");
 myMessage.add("äöü");       //placeholder for String array[0]
 myMessage.add("abcdefgh");  //placeholder for String array[1]...
 oscP5.send(myMessage, myRemoteLocation);
}

void oscEvent(OscMessage theOscMessage) {
 println("received an osc message.  "+theOscMessage.addrPattern());
 println(" typetag:  "+theOscMessage.typetag());
 println(theOscMessage.get(0).stringValue());  //prints ???  
 println(theOscMessage.get(1).stringValue());  //prints abcdefth
Re: OSCP5 string problem
Reply #1 - May 21st, 2008, 4:59pm
 
Unfortunately I think OSC is limited to plain ASCII strings by default.

You can work around this by encoding strings into byte[] and back again, e.g. with this modified version of oscP5sendreciee example:

Code:
import oscP5.*;
import netP5.*;

OscP5 oscP5;
NetAddress myRemoteLocation;

void setup() {
size(400,400);
frameRate(25);
oscP5 = new OscP5(this,12000);
myRemoteLocation = new NetAddress("127.0.0.1",12000);
}


void draw() {
background(0);
}

void mousePressed() {
OscMessage myMessage = new OscMessage("/test");
try {
byte[] b=(new String("Föô bár").getBytes("UTF-8"));
myMessage.add(b);
}
catch(Exception e) {
//couldn't encode...
}
oscP5.send(myMessage, myRemoteLocation);
}

void oscEvent(OscMessage theOscMessage) {
print("### received an osc message.");
print(" addrpattern: "+theOscMessage.addrPattern());
println(" typetag: "+theOscMessage.typetag());
byte[] b=theOscMessage.get(0).bytesValue();
String s="";
try {
s=new String(b,"UTF-8");
}
catch(Exception e){}
println("String: "+s);
}
Re: OSCP5 string problem
Reply #2 - May 21st, 2008, 6:00pm
 
Thank you very much, now it works properly.
Best regards.
Page Index Toggle Pages: 1