client.connected fails after successful client.connect

This code usually works to connect to Yahoo and get the time. However, it often fails at the client.connected test and will not proceed if I upload a new version of the sketch and try to restart it.

If I power off the Arduino Ethernet Uno and disconnect the USB cable from the PC and the Ethernet cable, and then wait a while (20 minutes?) and reconnect everything, it will then usually connect OK and get the time. Was hoping for something more elegant…

Sample print output when the Yahoo connection fails is:

Client connected
Failure at client.connected 1970 - client connected attempts : 1
Failure at client.connected 1970 - client connected attempts : 2
client connect failure - attempts = 1
Client connected
Failure at client.connected 1970 - client connected attempts : 1
Failure at client.connected 1970 - client connected attempts : 2
client connect failure - attempts = 2
Client connected
Failure at client.connected 1970 - client connected attempts : 1

etc until finally -
Client connected
Failure at client.connected 1970 - client connected attempts : 1
Failure at client.connected 1970 - client connected attempts : 2
client connect failure - attempts = 8
Failed to set time - system halted! attempts = 9 time = 1

If I reboot the router or the PC, that seems to get it running again and connecting OK. Any ideas what I am doing wrong?

Thanks!!
TimW

....
   Ethernet.begin(mac, ip, gateway, gateway, subnet);
....

boolean connectToYahoo() {
    attempts = 0;
    while (attempts++ < 8) {          // try 7 times to connect
      client.stop();
      delay(1000);
      if (client.connect(serverName, 80)) {
      client.println("GET /forecastrss?w=2357024 HTTP/1.0");
      client.println("Host: weather.yahooapis.com");
      client.println("Connection: close");
      client.println();
      Serial.println("Client connected");
      delay(500);       // not sure how long this needs to be - 1000 seems to work OK - changed to 2000
      cattempts = 0;
      while (cattempts++ < 2) {
      if (client.connected()) {  //a
        delay(100);
        if (client.available()) {  //b
          if (client.find("Date:")) {  //c
            if (client.find(", ")) {  //d
              byte found = client.readBytes(yahooTime,20);
              if (found != 0) {  //e
                dateString = yahooTime;   // convert from char to String to allow string calls below
                setTime(dateString.substring(12,14).toInt(),dateString.substring(15,17).toInt(),dateString.substring(18,20).toInt(),dateString.substring(0,2).toInt(),((monthNames.indexOf(dateString.substring(3,6)) / 3) + 1),dateString.substring(7,11).toInt());
                //adjustTime(-14400);       // set to Atlanta time from GMT: ATL = GMT minus 4 hours during the watering season
                return true;             // true means no error
              }  //e
              else {  //f
                Serial.println("cannot set time");
                return false;
              }  //f
            } //d
          }  //c
          Serial.println(" failure at client.find ");
          return false;  //error return
        } //b
        Serial.println(" failure at client.available ");
      }  //a
      else {                      // if you didn't get a connection to the server:
        Serial.print("  Failure at client.connected ");
        Serial.print(year());
        Serial.print(" - client connected attempts : ");
        Serial.println(cattempts);
        delay(10000);  // not sure if this is needed
      }
      }
      client.stop();
      delay(1000);
      }
      Serial.print("client connect failure - attempts = ");
      Serial.println(attempts);
    }    // end of while()
    client.stop();
    return false;             // give up - cannot connect
}
//------------------------------------------------------------------------------]