title: Arduino (Uno) Ethernet client connection fails after many client prints
body: <p>I'm using an Arduino Uno with Ethernet Shield.</p>
  
  <p>After sending many HTTP requests, <em>client.println(...)</em>, the client starts to fail when connecting. The time to failure appears to be random, and the sequence readout from the loop can vary anywhere between ~1000 and ~7000.</p>
  
  <p>The error is not to do with the Ethernet Transmit Buffer overflowing (Following <a href="http://arduino.cc/forum/index.php/topic,72027.0.html" rel="nofollow">this advice</a>)</p>
  
  <p>Here is the code that is failing:</p>
  
  <pre><code>#include &lt;Ethernet.h&gt;
  #include &lt;SPI.h&gt;
  
  // Network constants
  byte mac[] = {0x00, 0x23, 0xdf, 0x82, 0xd4, 0x01};
  byte ip[] = {/*REDACTED*/};
  byte server[] = {/*REDACTED*/};
  int port = /*REDACTED*/;
  Client client(server, port);
  
  // State
  int sequence;
  
  void setup(){
      Ethernet.begin(mac, ip);
      Serial.begin(9600);
      sequence = 0;
  
      delay(1000);
  }
  
  void loop(){
      httpPut("/topic/:test/publish?sessionId=SESenanhygrp");
      Serial.println(sequence++);
  }
  
  void httpPut(char* url){
      if (!client.connect()) {
          Serial.println("EXCEPTION: during HTTP PUT. Could not connect");
          return;
      }
  
      client.print("PUT");
      client.print(" ");
      client.print(url);
      client.println(" HTTP/1.0");
      client.println();
  
      while(!client.available()){
          delay(1);
      }
  
      while(client.available()) {
          char c = client.read();
          Serial.print(c);
      }
  
      while(client.connected()){
          Serial.println("Waiting for server to disconnect");
      }
  
      client.stop();
  }
  </code></pre>
  
  <p>The error occurs in the following segment</p>
  
  <pre><code>if (!client.connect()) {
      Serial.println("EXCEPTION: during HTTP PUT. Could not connect");
      return;
  }
  </code></pre>