Alterscape
Junior Member
Offline
Posts: 64
NY
Re: Communication between EyesWeb and Processing
Reply #30 - Sep 26th , 2005, 5:38pm
I've solved (at least to a preliminary extent) the threading issue with Manuel's implementation of Rune Andersen's eyesweb-p5 code. I'll post a zip file with my changes in the near future, but I've got to run to class soon, so I'll just describe what I did here. First, I downloaded the CubbyHole.java file from java.sun.com. This is a simple synchronized data structure. I modified it to store Objects instead of ints. Then I modified Manuel's version of Rune's eyeswebsocket.java to have a private CubbyHole object, and put the received data into that CubbyHole after it is received. I also added a getCubbyHole() method to retrieve the cubbyhole object for use by the main part of the program. Then I added the following code to my main Processing project file: public class Javaserver3 extends PApplet { eyeswebsocket myServer; private volatile Thread serverThread = null; CubbyHole myQueue; int[][] myMatrix; void setup() { size(800,600); myServer = new eyeswebsocket(7777); myQueue = myServer.getQueue(); myServer.Verbose=true; // No debug messages myServer.blocking=false; //change this to true to put it back the way it was myServer.waitconn(); if (serverThread == null) { serverThread = new Thread(myServer, "Server1"); serverThread.start(); } } void draw() { println("frame!"); background(0); fill(255,0,0); myMatrix = (int[][]) myQueue.get(); rect(myMatrix[0][0],myMatrix[1][0],myMatrix[2][0],myMatrix[3][0]); } } You should be able to figure out the important parts, but basically this sets up the eyeswebserver, then waits for a connection. Once the connection is detected, it creates a new thread to handle the data recieve stuff. The draw function just draws a rectangle (in this case, my input is a mocap entry converted to a matrix, so its the x, y, width, height of the rectangle). I hope this proves helpful; as I said, I'll make a more generalized version and post it in an archive later tonight. Ryan