Solved: Ethernet Shield: Error - Client connects only 3 times ....


is there something wrong with Arduino 1.0 library? I programmed a loop that should connect every 10 seconds to a server and put some data to it via GET. At the end of every loop I use Client.stop. After three loops the program cannot connect to to my server any more. Has anyone an idea?


Loop forever: Every 10 seconds do connect to server put some data: GET /data/data.php?X=100 HTTP 1.1 Client.println(); delay(1); Client.stop(); end time loop Loop

Is there anything wrong with logic? It seems to me that some buffer overflows or the maximum connections are getting off as the shield can handle 4 requests at one time.

It would help form me to get some sample code for a loop like above which worls.Thanks in advance

You are probably leaving characters in the rx buffer. The connection will not close until you empty it.

client.println("GET /data/data.php?X=100 HTTP/1.0");


Search the forum for zoomkat's client code.

Below is some new client test code you can try and see if you can get more than three request without a failure.

//zoomkat 2-13-12
//DNS and DHCP-based web client test code
//for use with IDE 1.0
//open serial monitor and send an e to test
//and to see test result
//for use with W5100 based ethernet shields
//browser equivelant URL: 

#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
char serverName[] = ""; // zoomkat's test web page server
EthernetClient client;


void setup(){
  Serial.println("DNS and DHCP-based web client test 2/13/12"); // so I can keep track of what is loaded
  Serial.println("Send an e in serial monitor to test"); // what to do to test
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
  // print your local IP address:
  Serial.print("Arduino IP address: ");
  for (byte thisByte = 0; thisByte < 4; thisByte++) {
    // print the value of each byte of the IP address:
    Serial.print(Ethernet.localIP()[thisByte], DEC);

void loop(){
  // check for serial input
  if (Serial.available() > 0) //if something in serial buffer
    byte inChar; // sets inChar as a byte
    inChar =; //gets byte from buffer
    if(inChar == 'e') // checks to see byte is an e
      sendGET(); // call sendGET function below when byte is an e


void sendGET() //client function to send/receive GET request data.
  if (client.connect(serverName, 80)) {  //starts client connection, checks for connection
    client.println("GET /~shb/arduino.txt HTTP/1.0"); //download text
    client.println(); //end of get request
  else {
    Serial.println("connection failed"); //error message if no client connect

  while(client.connected() && !client.available()) delay(1); //waits for data
  while (client.connected() || client.available()) { //connected or data available
    char c =; //gets byte from ethernet buffer
    Serial.print(c); //prints byte to serial monitor 

  client.stop(); //stop client


Hi Zoomkat, SurferTim,

thanks a lot for your support. Last code worked for me. As I reviewed my own code I found out a problem with my timer loop (shame....). Simple but effective: comparing a int var to a unsigned long will show curious results or nothing like in my case. Arduino works fine, Ethernet library works fine, Programmer should go for different work.


Programmer should go for different work.

Only if Programmer won't learn from his mistakes. 8)