O P5.js > websocket > Processing > OSC > Unity

Hi I need to send messages to different proccesing files and Unity + a websocket. I just can’t figure out how to send the received data from the websocket over to the processing file.

This is my websocket:

import websockets.*;

WebsocketServer ws;
float x,y;
float value;
JSONObject mouseCoords = new JSONObject();

void setup(){
size(400,400);
ws= new WebsocketServer(this,8080,"/processing");
mouseCoords = new JSONObject();
}

void draw(){
background(128);
ellipse(x,height/2,10,10);
}

void mouseMoved() {
float x = mouseX;
//y = mouseY;
//mouseCoords.setInt(“xPos”, x);
//mouseCoords.setInt(“yPos”, y);
//ws.sendMessage(mouseCoords.toString());
ws.sendMessage(x + “,” + y);
}

void webSocketServerEvent(String data){

 println("Received:" + data);
 JSONObject json = parseJSONObject(data);
 x = json.getInt("xPos");
 //y = json.getInt("yPos");
 println("Received:" + data);

 ws.sendMessage(data);

}

And this is my slider that needs the value:

import oscP5.;
import netP5.
;

OscP5 oscP5;
NetAddress myRemoteLocation;

// store incoming/outgoing value
float value;

// to display sending or receiving
String activity = “”;

void setup() {
size(400,100);
/* start oscP5, listening for incoming messages at port 8000 */
oscP5 = new OscP5(this,8000);

/* 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.
  • we send in this application to port 9000.
    */
    myRemoteLocation = new NetAddress(“127.0.0.1”,9000);
    }

void draw() {

background(64);

// display the value
rect(0,height/2,value*width,20);

text(activity + value,10,20);

if(value == 0.1){
ellipse(width/2,height/5,40,40);
fill(0,0,255);
}

if(value == 0.9){
ellipse(width/2,height/5,40,40);
fill(255,0,255);
}

}

void mouseClicked() {
sendMessage();
}

void mouseDragged() {
sendMessage();
}

void sendMessage() {

activity = "sending: ";

// normalize the value between 0.0 - 1.0;
value = mouseX/float(width);

OscMessage myMessage = new OscMessage("/fader");
myMessage.add(value);
oscP5.send(myMessage, myRemoteLocation);
}

/* incoming osc message are forwarded to the oscEvent method. */
void oscEvent(OscMessage theOscMessage) {

// only react on this addresspattern
if(theOscMessage.checkAddrPattern("/fader")==true) {

 // check if the value is a float
 if(theOscMessage.checkTypetag("f")) {
    activity = "receiving: "; 
   
    value = theOscMessage.get(0).floatValue();
 }

}
}