lukegeorge
Ex Member
OSCP5
Feb 19th , 2007, 9:26am
Hi, I'm having some trouble with this code I've written to send OSC messages to Supercollider and across a switch to two other machines. 1. I can't seem to bind addresses or values to OSC messages at all. You will notice in the routeData method i have place printlns to give me info on the contents of the message. Those statements which return information from the message come back null and the statement which is supposed to return the value of the first argument in the message throws a nullPointer Exception. 2. Im establishing connections across machines using OSCP5 TCP, however as soon as i connect from a client terminal which calls the routeData method i get an ArrayIndexOutOfBounds Exception at the server terminal. Hope someone out there can help! Thanks. Code: // Luke George // 3rd Year Music Informatics Bsc // January - March 2007 //Import necessary packages import oscP5.*; import netP5.*; public class DataRouter extends Thread{ //Create OSC supercollider client OscP5 scClient; //Create tcp server OscP5 server; //Create client A OscP5 clientA; //Create client B OscP5 clientB; //Create float arrays for data from remote locations float[] remoteData1, remoteData2; //Reference Strings for client addresses String clientAAddr, clientBAddr; //NetAddress object defining loopback for supercollider NetAddress loopBack; //Create bundle used to package data for remote locations OscBundle msgBundle; //Constructor public DataRouter(){ //Call to superclass constructor super("DataRouter"); // Local OSC traffic to SC goes via UDP scClient = new OscP5(this, 6969); //loopback address for Supercollider loopBack = new NetAddress("127.0.0.1", 57120); //Network OSC traffic travels by TCP server = new OscP5(this, 5000, OscP5.TCP); //Initialise msgBundle msgBundle = new OscBundle(); //Initialise data array and fill with 0s remoteData1 = new float[3]; for(int i = 0; i < remoteData1.length; i = i + 1){ remoteData1[i] = 0; } //Initialise data array and fill with 0s remoteData2 = new float[3]; for(int i = 0; i < remoteData1.length; i = i + 1){ remoteData2[i] = 0; } //Start the Thread this.start(); } //boot sets up the client connections to the other machines. //This method is user triggered since servers must be running //on remote machines for connections to be established void boot(String clientAAddr, String clientBAddr){ this.clientAAddr = clientAAddr; this.clientBAddr = clientBAddr; println(); println("Booting..."); //Attempt to create client connection A println(); println("Contacting clientA: "+clientAAddr); clientA = new OscP5(this, clientAAddr, 5000, OscP5.TCP); delay(1000); //Attempt to create client connection B println(); println("Contacting clientB: "+clientBAddr); clientB = new OscP5(this, clientBAddr, 5000, OscP5.TCP); delay(1000); } //Method used to route data locally (supercollider) and also to //remote locations. Data arriving is immediately despatched via //OSC to supercollider locally. Every third call, i.e. when //values for all 3 sensors are present a bundle is sent via OSC to //remote locations void routeData(float[] data){ for(int i = 0; i < data.length; i = i + 1){ String addr = "/sens"+i; println("Address: "+addr); float value = (0.5*data[i]) + (0.25*remoteData1[i]) + (0.25*remoteData2[i]); println("Value: "+value); OscMessage message = (addr); message.add(value); println("Address: "+message.address()); println("Value: "+message.get(1).floatValue()); <<<< BOMBS OUT HERE scClient.send(message, loopBack); msgBundle.add(message); } clientA.send(msgBundle); clientB.send(msgBundle); msgBundle.clear(); } //OSC event listener void oscEvent(OscBundle msgBundle){ System.out.println("Received OSC Bundle"); } void shutDown(){ scClient.stop(); delay(100); server.stop(); delay(100); clientA.stop(); delay(100); clientB.stop(); delay(100); println("Services stopped"); } }