Processing and the Internet
In the Processing website I found out this piece of code that requests the HTTP headers of a page and prints out the results:
I will report here the code which is shown on the Processing website at this address: HTTP CLIENT
import processing.net.*;
Client client;
void setup()
{
size(200, 200);
noStroke();
// Open a TCP socket to the host:
client = new Client(this, "processing.org", 80);
// Print the IP address of the host:
println(client.ip());
// Send the HTTP GET request:
client.write("GET /index.html HTTP/1.1n");
client.write("HOST: processing.orgnn");
}
void draw()
{
background(0);
// Print the results of the GET:
if (client.available() > 0) {
int inByte = client.read();
print((char)inByte);
} else {
println("nnThat's all, folks!n");
}
}
So we will go piece by piece and try to understand what id does
// First line imports the net library which comes // embedded into the Processing client software.import processing.net.*;// Defines a default client Client client; void setup() {// Opens a window of 200 by 200 pixels size(200, 200);// Delete the border; noStroke(); // Open a TCP socket to the host: client = new Client(this, "processing.org", 80); // Print the IP address of the host: println(client.ip()); // Send the HTTP GET request: client.write("GET /index.html HTTP/1.1n"); client.write("HOST: processing.orgnn"); } void draw() { background(0); // Print the results of the GET:// Check if the website is online and Processing gets an answer if (client.available() > 0) { int inByte = client.read(); //writes the number of Bytes read print((char)inByte); } else { println("nnThat's all, folks!n"); } }
This may be helpful on the completion of my assignment, but still I will have to find a way to output these data into the Arduino board, and most important of all, I need to set a range of Voltage output, otherwise my game will get in fire.
Please note that the code is available at this address: Processing HTTP CLIENT .
No Comments
No comments yet.
Comments RSS TrackBack Identifier URI
Sorry, the comment form is closed at this time.
