OSC simple example support using Ketai or not

edited March 2016 in Android Mode

Just tinkering around. Recently I'm trying to make a simple example where two processing apps talk to each other over OSC (One running in android phone and the other in my computer)..

Now I first tried two apps both running in my computer (Both on local network 127.0.0.1 and swapped their ports) Here are the codes: Message sender (which send a random number every-time you mouse click in the applet window)

import oscP5.*;
import netP5.*;

OscP5 oscP5;
NetAddress myRemoteLocation;

float val;

void setup() {
  size(200, 200);

  /* start oscP5, listening for incoming messages at port 12000 */
  oscP5 = new OscP5(this, 12000);

  /* myRemoteLocation is a NetAddress. a NetAddress takes 2 parameters,
   * an ip address and a port number. myRemoteLocation is used as parameter in
   * oscP5.send() when sending osc packets to another computer, device, 
   * application. usage see below. for testing purposes the listening port
   * and the port of the remote location address are the same, hence you will
   * send messages back to this sketch.
   */
  myRemoteLocation = new NetAddress("127.0.0.1", 8000);
}


void draw() {
  background(255);
}

void mousePressed() {
  //constitute message:
  OscMessage myMessage = new OscMessage("/print");
  myMessage.add(random(10, 100));
  oscP5.send(myMessage, myRemoteLocation);
}

On the other hand the receiver processing app is kind of like this:

import oscP5.*;
import netP5.*;

OscP5 oscP5;
NetAddress myRemoteLocation;

float val;

void setup() {
  size(200, 200);

  /* start oscP5, listening for incoming messages at port 8000 */
  oscP5 = new OscP5(this, 8000);
  myRemoteLocation = new NetAddress("127.0.0.1", 12000);
}


void draw() {
  background(0);
}

void oscEvent(OscMessage theOscMessage) {
 val = theOscMessage.get(0).floatValue();
 println("Val: " + val);
} 

Now they seem to work on the computer ..

I imagined when porting it for android, I should just hardcode the ip-addresses .. But it doesn't work .. Tried to look at some help from the ketai library , but there's no direct example for a simple communication.. One example(wifi_direct_remote_cursor) explains but it's very scattered. I couldn't understand why I need to check if I was on the same network and get client addresses and all ..

Can someone help me establish a simple example like above below , The message sender is the Android app and the message receiver is the computer app ..

Thanks in advance ..

Sign In or Register to comment.