1/**
2 * HTTP Client.
3 *
4 * Starts a network client that connects to a server on port 80,
5 * sends an HTTP 1.0 GET request, and prints the results.
6 *
7 * Note that this code is not necessary for simple HTTP GET request:
8 * Simply calling loadStrings("http://www.processing.org") would do
9 * the same thing as (and more efficiently than) this example.
10 * This example is for people who might want to do something more
11 * complicated later.
12 */
13
14
15import processing.net.*;
16
17Client c;
18String data;
19
20void setup() {
21  size(200, 200);
22  background(50);
23  fill(200);
24  c = new Client(this, "www.processing.org", 80); // Connect to server on port 80
25  c.write("GET / HTTP/1.0\r\n"); // Use the HTTP "GET" command to ask for a Web page
26  c.write("\r\n");
27}
28
29void draw() {
30  if (c.available() > 0) { // If there's incoming data from the client...
31    data = c.readString(); // ...then grab it and print it
32    println(data);
33  }
34}
35
36