CODIGO SERVIDOR

Este es el código que realizamos para desarrollar nuestro proyecto de cadáver interactivo, fue realizado en el software processing.


import processing.net.*;

Server s;

PFont font;

float posx = 0;

float posy = 20;

Client c;

String input;//Aqui se guardara la posicion remota

int letter;

String data[];

String buff= "";

void setup()

{

size(500, 500);

background(255);

font = loadFont("Arial.vlw");

textFont(font, 36);

frameRate(30); // Slow it down a little

s = new Server(this, 54321); // Start a simple server on a port

}

void draw(){

// Receive data from client

c = s.available();

if (c != null) {

// println(c.ip());

input = c.readString();

//input = input.substring(0, input.indexOf("\n")); // Only up to the newline

data = (split(input, ' ')); // Split values into an array

fill(0);

text(data[0], posx, posy);

posx = posx + textWidth(data[0]);

print(posx);

if(posx > width-textWidth(data[0])){

posx = 0;

posy = posy + 30;

}

else{

posx = posx + textWidth(data[0]);

}

}

}

void serverEvent(Server s, Client c) {

println("We have a new client: " + c.ip());

}

void keyPressed(){

fill(0);

buff = buff+char(key);

//println(buff);

if (keyCode == ENTER){

println(buff);

if(posx > width-textWidth(buff)){

posx = 0;

posy = posy + 20;

}

else{

posx = posx + textWidth(buff);

}

print(posx);

text(buff, posx, posy );

buff = "";

}

}


Este código fue creado para recibir datos (letras y números) de clientes, posicionarlos y publicarlos en orden como van llegando de cada cliente, De la misma forma le asigna un color diferente a cada cliente para reconocer de quien es cada línea de datos mandada


ESPACIOS INTERACTIVOS