
import processing.net.*; 

Client myClient; 
String dataIn;
int state;

String hostname;
int port;

final int IDLE = 1;
final int GET_IN_PROGRESS = 2;


void setup() { 
  size(200, 200); 
  // Connect to the local machine at port 5204.
  // This example will not run if you haven't
  // previously started a server on this port.
  hostname = "damien.sauveron.fr";
  port = 80;
  myClient = new Client(this, hostname, port);
  state = IDLE;
} 

void mouseClicked() {
  String yourInput;
  switch(state)
  {
  case IDLE:
    yourInput = askString("Veuillez saisir l'URI souhaité ?");
    if (yourInput == null || yourInput.equals("")) {
      yourInput = "/";
    }
    myClient.write("GET "+yourInput+" HTTP/1.1\r\n");
    myClient.write("Host: "+hostname+"\r\n\r\n");
    state = GET_IN_PROGRESS;
    break;
  }
  
}

void draw() { 
  if (myClient.available() > 0) { 
    dataIn = myClient.readString();
    switch(state)
    {
    case GET_IN_PROGRESS: 
      state = IDLE;
      break;
    }
    println(dataIn);
  }
} 
