Infinite Loop when checking Client.connected()?

#if defined(ARDUINO) && ARDUINO > 18
#include <SPI.h>
#endif
#include <Ethernet.h>
#include <EthernetDHCP.h>


//RF Includes
#include <Mirf.h>
#include <MirfHardwareSpiDriver.h>
#include <MirfSpiDriver.h>
#include <nRF24L01.h>

//RF Pins
/*

*Pins SPI 
*MISO -> 50
*MOSI -> 51
*SCK  -> 52
*SS   -> 53

CE  -> 8
CSN -> 7

*/

//Ethernet Pins
/*

*Pins SPI 
*MISO -> 50
*MOSI -> 51
*SCK  -> 52
*SS   -> 53* Still pin 10?

CE  -> 8
CSN -> 7

*/


// MAC Address
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

const char* ip_to_str(const uint8_t*);
const char* hostName();
int setHostName(const char* newHostName);
// Initialize the Ethernet server library
//Server server(8080);

int localstatus = 0; //status
int oldgatestatus;
int gatestatus = 0; //old status
int s;

//INTERRUPTS
int pbIn = 0;                  // Interrupt 0 is on DIGITAL PIN 2!
volatile int state = LOW;      // The input state toggle


byte serverip[] = { 142, 55, 49, 114 };
Client client(serverip, 80); //apache web server running on port 80

//enable the ethernet chip on the SPI bus

void EtherSelect(){
  digitalWrite(10, LOW);//Ether_CS
  digitalWrite(22, HIGH); //Ether_Sel
  EthernetDHCP.maintain();
}

//disable the ethernet chip on the SPI bus
void EtherDeselect(){
  digitalWrite(10, HIGH);
  digitalWrite(22, LOW);
}

void RFInit()
{
  EtherDeselect();
  //digitalWrite(22, LOW);
  /* Set additional pin inputs and outputs*/
  //pinMode (2,INPUT);
  //pinMode (3,INPUT);
  
  /* SPI DRIVER */
  Mirf.spi = &MirfHardwareSpi;
  Mirf.csnPin = 25;
  Mirf.cePin = 23;
  /*Intialize ce and csn pins*/
  Mirf.init();
  
  /*set Receiving address - data pipe 1 -5 byte maximum */
  Mirf.setRADDR((byte*)"goat1");
  
  /*set Transmitting address - data pipe 1 - 5 byte maximum */
  Mirf.setTADDR((byte*)"send1");
  
  /* Set payload length - Note* payload on client and server must be the same!!! */
  Mirf.payload = 1;/*sizeof(byte);
  
  /* set to channel 90 (Avoid wifi/ wireless cameras) payload will remain at 16 bytes then power up clear RX register of nrf2401 */
  Mirf.channel = 90; 

  Mirf.config();
  
  // Set 1MHz data rate (Longer Range)
 // Mirf.configRegister(RF_SETUP,0x06);
  EtherSelect();
  
   //digitalWrite(22, HIGH);
  Serial.println("RF has begun ...");
}

int RFRead(int)
{
  Serial.println("Sending RF Signal");
  EtherDeselect();

//   if (digitalRead(24) == HIGH)
//  {
//    Serial.println("high detected1 TURN ON");
    if (localstatus == 1)
    {
      localstatus = 0;
       Serial.println("high detected2 TURN OFF");
    
    byte data1 = B00111100;
    
      Mirf.send((byte*)&data1);
  
      while(Mirf.isSending())
      delay(450);
      EtherSelect();
      return 0;
    }
    else
    {
      localstatus = 1;
      Serial.println("high detected2 TURN ON");
      byte data1 = B01111100;
    
      Mirf.send((byte*)&data1);
  
      while(Mirf.isSending())
      {
      }
      delay(450);
       // digitalWrite(22, HIGH);
      EtherSelect();
      return 1;
    }
    
      
//  }
 

}

void stateChange()
{
  delay(110);
state = !state;
localstatus = RFRead(localstatus);
Serial.println("Localstatus from interrupt is:");
Serial.println(localstatus);

if  (digitalRead(10) == HIGH){//If ethernet disabled
Serial.println("Enabling Ethernet");
EtherSelect();
send_to_server();
Serial.println("Done sending to server, deselecting internet");
EtherDeselect();
}
else{
  Serial.println("Preparing to send to server, ethernet already enabled");
send_to_server();
}
}

void setup()
{
  //Attach the interrupt to the input pin and monitor for ANY Change
  attachInterrupt(pbIn, stateChange, RISING);
  pinMode(22, OUTPUT);
  
 // pinMode(53, OUTPUT);
  Serial.begin(9600);
  //pinMode (2,INPUT); //test pin buton
  //pinMode (A2,INPUT);
  Serial.println("Attempting to obtain a DHCP lease...");
  
  RFInit();
 
  EthernetDHCP.begin(mac);

  // Since we're here, it means that we now have a DHCP lease, so we print
  // out some information.
  const byte* ipAddr = EthernetDHCP.ipAddress();
  const byte* gatewayAddr = EthernetDHCP.gatewayIpAddress();
  const byte* dnsAddr = EthernetDHCP.dnsIpAddress();
  
  Serial.println("A DHCP lease has been obtained.");

  Serial.print("My IP address is ");
  Serial.println(ip_to_str(ipAddr));
  
  Serial.print("Gateway IP address is ");
  Serial.println(ip_to_str(gatewayAddr));
  
  Serial.print("DNS IP address is ");
  Serial.println(ip_to_str(dnsAddr));
  
  // Start the server
   Serial.println("Starting Server.");
   //server.begin();
}

void loop()
{

EthernetDHCP.maintain();
Serial.println("Comparing Server Status"); 
gatestatus = oldgatestatus;
gatestatus = readvalues(); 
/*if (digitalRead(24) == HIGH)
{
  localstatus = RFRead(localstatus);
}
else
{
  localstatus = gatestatus;
}
*/

Serial.println();
Serial.println();
Serial.println();
Serial.println("Gatestatus:");
Serial.println(gatestatus);
Serial.println();
Serial.println();
Serial.println("Localstatus:");
Serial.println(localstatus);
Serial.println();
Serial.println();


 if (localstatus!= gatestatus || gatestatus != oldgatestatus){
   if (gatestatus != oldgatestatus)
   {
   Serial.println("Statuses are not equal");
        localstatus = gatestatus; 
    }
    send_to_server();
      
      
    
      Serial.println("Gate Status is");
      Serial.println(gatestatus);
      
 
    // give the web browser time to receive the data
    delay(500);
    // close the connection:
    client.stop();
  }
}

// Just a utility function to nicely format an IP address.
const char* ip_to_str(const uint8_t* ipAddr)
{
  static char buf[16];
  sprintf(buf, "%d.%d.%d.%d\0", ipAddr[0], ipAddr[1], ipAddr[2], ipAddr[3]);
  return buf;
}

int readvalues()
{
    Serial.println("In Read Values");
    while(1){
    if (client.connect()) {
    Serial.println("Readvalues client connected");
    client.println("GET /headgateget.php");
    client.print( millis() );          // prevent caching, like justjed said a post before
    client.println("HTTP/1.0");                // no need for 1.1
    client.println("Host: cs14.sheridanc.on.ca");
    client.println("Connection: close");
    client.println();
   //delay(7);
    while (client.connected()){
      if (client.available()) {
      Serial.println("client is avaliable printing page");
      char c = client.read();
      Serial.println("parsed page, C=");
      Serial.println(c);
      delay(100);
      s = c - '0';
      Serial.println("S is equal to:");
      Serial.println(s);
      return s;
      }
    }
    }
    
    
    if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    return localstatus;
    client.stop();
    
    
    }
    }
}

void send_to_server()
{
  
  while(1){
  Serial.println("sending to server function");
 Serial.println(client.connect());
if (client.connect()) {
   
          Serial.println("Set Server connected");
          
          client.print("GET /headgatetestset.php?Status=");     // Path only, not the complete URI   
          client.print(localstatus);
          client.print("&");
          client.print( millis() );          // prevent caching, like justjed said a post before
          client.println(" HTTP/1.0");                // no need for 1.1
          client.println("Host: cs14.sheridanc.on.ca");
          client.println("Connection: close");
          client.println();
          Serial.println("posted to db");
          return;


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

I have this code to control an LED using an RF Transiever. I programmed a button as an interrupt to flash the led and it worked. Now I am also trying to update a webserver with the status of the LED and when the status is changed by either the button or on the server then the light should act accordingly. The problem is that when it goes into the send_to_server() function it gets caught in an infinite loop. If (Client.connected()) and if (!Client.connected()) are both not true , how is this possible?

The RF code and the webserver code worked perfectly when it was not also checking for changes on the website. (It uploaded the changes that the button press made just fine).

localstatus is the button status
oldgatestatus is the status found online from the last time the page was called on
gatestatus is the up to date status that is found on line

Also I have to manually deselect and select the ethernet wiznet shield because of the spi bug.

In your if(!client.connected()) statement, there's nothing to break out of the while(1) loop you did earlier. While do you have the while(1) loop, anyway? If it's connected, you only go through one iteration before returning, and if it's not connected you stop the connection and probably want to break out of the loop immediately also.

I want it to go through that loop until it connects, also in the if(!client.connected()) statement it also prints disconneted to the serial monitor, but when i run the program it posts this Serial.println("sending to server function"); to the serial monitor over and over. Thats what doesnt make sense to me, that neither if statement is true :S