We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm trying to connect an Android device with a Processing sketch running on my laptop via the oscP5 library.
I'm doing the following:
I get this error in the Android sketch:
### [2013/12/13 18:39:51] PROCESS @ OscP5 stopped.
### [2013/12/13 18:39:51] ERROR @ UdpClient.openSocket cant create socket socket failed: EACCES (Permission denied)
### [2013/12/13 18:39:52] ERROR @ UdpServer.start() IOException, couldnt create new DatagramSocket @ port 9999 java.net.SocketException: socket failed: EACCES (Permission denied)
### [2013/12/13 18:39:52] INFO @ OscP5 is running. you (ERROR) are listening @ port 9999
My "oscAndroidReceiver" (the Android Sketch) does following (it changes the background color deppending on the message received):
/**
* oscAndroidReceiver
*/
import oscP5.*;
import netP5.*;
OscP5 oscP5;
color bgColor;
NetAddress myRemoteLocation;
void setup() {
size(400,400);
// start oscP5, listening for incoming messages at port 9999
oscP5 = new OscP5(this, 9999);
myRemoteLocation = new NetAddress("192.168.1.34", 9999);
// Processing receiver (Laptop)
bgColor = #FFFFFF;
}
void draw() {
background(bgColor);
}
void mousePressed(){
OscMessage myMessage = new OscMessage("/test");
myMessage.add(1);
oscP5.send(myMessage, myRemoteLocation);
}
/* incoming osc message are forwarded to the oscEvent method. */
void oscEvent(OscMessage theOscMessage) {
/* print the address pattern and the typetag of the received OscMessage */
print("### received an osc message.");
print(", addrpattern: "+theOscMessage.addrPattern());
print(", typetag: "+theOscMessage.typetag());
println(", value: "+theOscMessage.get(0).intValue());
int value = theOscMessage.get(0).intValue();
if (value == 1) {
bgColor = #FF0000;
} else if (value == 2) {
bgColor = #00FF00;
} else if (value == 3) {
bgColor = #0000FF;
} else if (value == 4) {
bgColor = #FFFFFF;
}
}
And the sender (the Processing sketch in my laptop) is doing following (it sends a code when typing "r", "g", "b", "w"):
/**
* oscKeyboardSender
*/
import oscP5.*;
import netP5.*;
OscP5 oscP5;
NetAddress androidLocation;
void setup() {
size(400,400);
frameRate(25);
// start oscP5, listening for incoming messages at port 8888
oscP5 = new OscP5(this, 8888);
// Location of my Android Device
androidLocation = new NetAddress("192.168.1.34", 9999);
}
void draw() {
background(0);
}
void keyPressed() {
/* in the following different ways of creating osc messages are shown by example */
OscMessage myMessage = new OscMessage("/bgcolor");
if (key == 'r') {
myMessage.add(1);
} else if (key == 'g') {
myMessage.add(2);
} else if (key == 'b') {
myMessage.add(3);
} else if (key == 'w') {
myMessage.add(4);
} else {
return;
}
println("Message sent with color: " + key);
/* send the message */
oscP5.send(myMessage, androidLocation);
}
Have anybody a tip?
Thanks for your help!
Answers
try.. put a delay in the setup here
I tried it but I still get this error in Android Mode:
It's strange. I checked with TouchOSC and when I send something from the sender sketch in my laptop TouchOSC seems to get an income message. I also tried with the oscP5broadcaster and oscP5broadcastClient examples and I get the same error.
Do I need to edit some permissions in my Android device?
If I am correct, the problem is here:
You need to add the
INTERNET
permission to your Android sketch (Android > Sketch Permissions in the PDE). Android is highly restrictive in this way.Yes, I wanted to post it. I could solve it adding this line :)
<uses-permission android:name="android.permission.INTERNET"/>