Este es el código que realizamos para desarrollar nuestro proyecto de cadáver interactivo, fue realizado en el software processing
import processing.net.*;
PFont font;
Client c;
String input;//Aqui se guardara la posicion remota
int letter;
float posx = 0;
float posy = 20;
int data[];
String buff= "";
{
size(500, 250);
background(255);
font = loadFont("Arial.vlw");
textFont(font, 36);
frameRate(30); // Slow it down a little
c = new Client(this,"localhost", 54321); // Start a simple server on a port
}
void draw(){
// Receive data from client
if (c.available() > 0) {
if (c != null) {
// println(c.ip());
input = c.readString();
//input = input.substring(0, input.indexOf("\n")); // Only up to the newline
data = int(split(input, ' ')); // Split values into an array
println(data);
fill(0);
text(char(data[0]), int(data[1]), int(data[2]));
}
}
}
void keyPressed(){
fill(0);
buff = buff+char(key);
//println(buff);
if (keyCode == ENTER){
println(buff);
text(buff, posx, posy );
if(posx > width-textWidth(buff)){
posx = 0;
posy = posy + 20;
}
else{
posx = posx + textWidth(buff);
}
c.write(buff +" "+ posx +" "+ posy);
buff = "";
}
}
Este es el código para los clientes, el cual se encarga de almacenar lo datos que se escriben (letras y números), para ser mandados a el servidor. Básicamente recibe datos los almacenan y se mandan al servidor.