We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpElectronics,  Serial Library › Problems setting up network library example online
Page Index Toggle Pages: 1
Problems setting up network library example online (Read 846 times)
Problems setting up network library example online
Nov 23rd, 2009, 9:57am
 
Hi,

I have been playing with this continually in many variations for the last few days and can't find the answer. Hopefully someone else has tried this and succeeded. I am attempting to upload the networks library example from Daniel Shiffman online to receive data from a local computer (in an office).

Here is my attempt at reversing the examples (in the given examples the server sends information to the to the client and the client does something in the draw function using the data).

The server code (online):
Code:
// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com

// Example 19-4: Client reading values as background color

// Import the net libraries
import processing.net.*;
// Declare a client
Server server;
// The data we will read from the server
int data;

void setup() {
size(200,200);

server = new Server(this, 5204);

}


void draw() {

// Read data
server.read(data);

// The incoming data is used to color the background.
background(data);

}

// The serverEvent function is called whenever a new client connects.
void serverEvent(Server server, Client client) {
println(" A new client has connected: "+ client.ip());
}



The Client code (running on a local computer):
Code:
// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com

// Example 19-3: Server broadcasting a number (0-255)

// Import the net libraries
import processing.net.*;

// Declare a server
Client client;
PFont f;
int data = 0;

void setup() {
size(200,200);

client = new Client(this,"IP ADDRESS HERE", 80); // Create the Client
client.write("GET /public_html/applet/index.html HTTP/1.0\n"); // use the HTTP "GET" command to ask for a web page
client.write("Host: WEBSITE HERE\n\n"); // Be polite and say who you are
//client = new Client(this, "127.0.0.1", 5204);
f = createFont("Arial",20,true);

}

void draw() {
background(255);

// Display data
textFont(f);
textAlign(CENTER);
fill(0);
text(data,width/2,height/2);

if (client.available() > 0) {
client.write(data);
}

data = (data + int(random( -2,4))) % 256;

}
Page Index Toggle Pages: 1