Ethernet Shield and Multiple GET requests/connects

I'm trying to call multiple GET requests to get the pages multiple times in a loop.

But it seems when running again client.connect() returns false. I have also tried running the GET request outside of the if(client.connect()) statement, but no luck (though the GET request sent via ethernet, no server response).

It does seem that client.connected() returns true.
How do you go about running multiple GET requests/connects?

Also I have included the Wireshark packet dump:
http://dl.getdropbox.com/u/263645/Arduino/packetdumpWebClientTest5Oct2009.pcap

#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 2, 2 };
byte subnet[] = { 255, 255, 255, 0 };    //subnet mask of the network
byte gateway[] = { 192, 168, 2, 1 };   //your router's IP address
byte server[] = { 74, 52, 17, 79 }; // Google

Client client(server, 80);

void setup()
{
  Ethernet.begin(mac, ip, gateway, subnet);
  Serial.begin(9600);
  
  delay(1000);
  
  Serial.println("connecting...");
  
 
}

void loop()
{
  
  if (client.connect()) {
      
      Serial.println("connected");
      client.println("GET / HTTP/1.0");
      client.println();
      
  } else {
      
      Serial.println("connection failed");
  }
    delay(1000);
    client.flush(); 

  
  
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    for(;;)
      ;
  }
}

Don't forget to use client.stop when the client is/has connected...

void loop()
{

  if (client.connect()) {

      Serial.println("connected");
      client.println("GET / HTTP/1.0");
      client.println();

  } else {

      Serial.println("connection failed");
  }
    delay(1000);
    client.flush();



  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    for(;;)
      ;
  }
[glow]   else 
    client.stop();[/glow]}

After a moment of thought while hitting the Post button, another thought came to me...

If you are attempting to keep the session alive, add the keep-alive header, otherwise the server will disconnect you after the first page has been sent.

Check the HTTP protocol for more information on that header...

Thank you so much Spinlock.

Yup, both of the solutions work :slight_smile:

I managed to get an LED controlled via Web. Though I'm currently trying to use the arduino web server instead of using the web client to change the LED lights.

Though I'm having issues defining the client variable as a public variable so that in can be accessed outside of the loop class.

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1255197934/0#0