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 & HelpOther Libraries › Looping HTTP requests
Page Index Toggle Pages: 1
Looping HTTP requests (Read 330 times)
Looping HTTP requests
Mar 17th, 2008, 5:56am
 
Hello,
I am a newbie and I'm playing with processing and interfacing to my arduino. I'm trying to loop HTTP requests so that I can monitor a value on a webpage and write it out to the serial port at regular intervals. This is essentially what Tom Igoe does in the book "making things talk" but he does it with an Xport instead of with processing. I'm using the code from the example page (below) but I'd like to move the GET request into the draw loop. This seems to cause errors. I've tried adding a stop() to close the connection server at the end of the loop with no luck. Thanks for any thoughts you may have.

Scott

import processing.net.*;

Client c;
String data;

void setup() {
 size(200, 200);
 background(50);
 fill(200);
 c = new Client(this, "www.processing.org", 80); // Connect to server on port 80
 c.write("GET / HTTP/1.1\n"); // Use the HTTP "GET" command to ask for a Web page
 c.write("Host: my_domain_name.com\n\n"); // Be polite and say who we are
}

void draw() {
 if (c.available() > 0) { // If there's incoming data from the client...
   data = c.readString(); // ...then grab it and print it
   println(data);
 }
}
Page Index Toggle Pages: 1