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 & HelpSyntax Questions › loadString and http error 400 - delay
Page Index Toggle Pages: 1
loadString and http error 400 - delay (Read 263 times)
loadString and http error 400 - delay
Feb 12th, 2009, 7:49pm
 
Hello!
I'm working on a project wich loads a large amount of webpages via the loadString function. It works well but if a webpage returns an http error, the thread stops for a few seconds before loading the rest of the pages. Is there a way to avoid that?
Re: loadString and http error 400 - delay
Reply #1 - Feb 12th, 2009, 10:05pm
 
You can use HEAD to get a fast status.
Demonstration:
Code:
import processing.net.*;

Client client;
int step = 0;

void setup()
{
 size(200, 200);
 frameRate(1);
 step = 1;
}

void draw()
{
 if (step > 0)
 {
   println("------ " + step);
   client = new Client(this, "www.processing.org", 80);
 }
 switch (step)
 {
 case 1:
   // 400 Bad Request (no Host)
   client.write("HEAD / HTTP/1.1\r\n\r\n");
   break;
 case 2:
   // 404 Not Found
   client.write("HEAD /index.html HTTP/1.1\r\n");
   client.write("Host: processing.org\r\n\r\n");
   break;
 case 3:
   // 200 OK
   client.write("HEAD / HTTP/1.1\r\n");
   client.write("Host: processing.org\r\n\r\n");
   break;
 case 4:
   // 200 OK (with content)
   client.write("HEAD /discourse/index.html HTTP/1.1\r\n");
   client.write("Host: processing.org\r\n\r\n");
   break;
 case 5:
   // 200 OK (dynamic page answer)
   client.write("HEAD /discourse/yabb_beta/YaBB.cgi HTTP/1.1\r\n");
   client.write("Host: processing.org\r\n\r\n");
   break;
 case 6:
   // 301 Moved
   client.write("HEAD /source/index.cgi HTTP/1.1\r\n");
   client.write("Host: dev.processing.org\r\n\r\n");
   break;
 case 7:
   exit();
 }
 if (step > 0)
 {
   step = -++step;
 }
 if (client.available() > 0)
 {
   String dataIn = client.readString();
   println(dataIn);
   step = -step;
 }
}
Page Index Toggle Pages: 1