tacitdynamite
YaBB Newbies
Offline
Posts: 43
NE
Re: same-server http requests
Reply #3 - Dec 15th , 2008, 4:12am
Hi, I finally got it to work. See [http://www.myernore.com/dev/processing/URL_test_7/] for the result. The main thing I was getting wrong: I duplicated the host name in the GET request, and included too many newlines in the GET request. I still don't know how to request the root from my server; I see in the examples that you can request the root of processing.org's server by doing simply "GET / HTTP/1.1\n" - in other words, the / stands for the root as it does in unix systems. On my host, however, / returns a 404, even though I have it defined ... Thanks for your help ... //////////////////////////////////////////// /** * HTTP Client. * * Starts a network client that connects to a server on port 80, * sends an HTTP 1.1 GET request, and prints the results. */ import processing.net.*; import java.lang.StringBuilder; import java.applet.Applet; Client c; StringBuilder data; PFont font; String host, file; PVector start, change; void setup() { start = new PVector(0,0); change = new PVector(0,0); Applet thisApplet = (Applet)this; host = thisApplet.getDocumentBase().getHost(); file = thisApplet.getDocumentBase().getFile(); size(600, 600); background(50); fill(200); textFont( createFont( "arial", 18 ) ); data = new StringBuilder(); c = new Client(this, host, 80); // Connect to server on port 80 c.write("GET " + file + " HTTP/1.1\n"); // Use the HTTP "GET" command to ask for a Web page c.write("Host: " + host + "\n\n"); // Be polite and say who we are } void draw() { translate( change.x, change.y ); cursor(MOVE); background( 50 ); fill( 200 ); if (c.available() > 0) { // If there's incoming data from the client... data.append( c.readString() ); // ...then grab it and print it } text( data.toString(), 10, 10 ); } void mouseDragged() { change.x += mouseX - pmouseX; change.y += mouseY - pmouseY; }