Arduino disconnected from webserver

My project is to connect the Arduino to web-server in order to light up an LED through the web, everything work fine with me, the Arduino is fully connected to the server and the LED light when a request from the website recieved. The only problem I'm facing is the connection to the server is disconnected immediately.

This is my code:

#include <SPI.h>
#include <WiFi.h>

char ssid[] = "HomeBroadband"; //  your network SSID (name)
char pass[] = "h12345678";    // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0;            // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128);  // numeric IP for Google (no DNS)
char server[] = "daffostore.com";    // name address for Google (using DNS)

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
WiFiClient client;

void setup() {
  //Initialize serial and wait for port to open:
  pinMode(8,OUTPUT);
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);
  }

  String fv = WiFi.firmwareVersion();
  if (fv != "1.1.0") {
    Serial.println("Please upgrade the firmware");
  }

  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }
  Serial.println("Connected to wifi");
  printWifiStatus();

  Serial.println("\nStarting connection to server...");
  // if you get a connection, report back via serial:
  if (client.connect(server, 80)  == 1) {
    Serial.println("connected to server");
    // Make a HTTP request:
    client.println("GET /ardd/ledstatus.txt HTTP/1.1");
    client.println("Host: daffostore.com");
    client.println("Connection: keep-alive");
    //client.println("Content-Length: 1845");
    client.println("Keep-Alive: timeout=10, max=20");
    client.println();
  }
}

void loop() {
  // if there are incoming bytes available
  // from the server, read them and print them:
  while (client.available()  && status == WL_CONNECTED) {
    char c = client.read();
    Serial.write(c);

    if(c=='1'){
      digitalWrite(8, HIGH);
      }
      else{
        digitalWrite(8, LOW);
        }


  }



  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting from server.");
    client.stop();

    // do nothing forevermore:
    while (true);
  }
}


void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

and this is the serial monitor output:

Attempting to connect to SSID: HomeBroadband
Connected to wifi
SSID: HomeBroadband
IP Address: 192.168.1.12
signal strength (RSSI):-54 dBm

Starting connection to server...
connected to server
HTTP/1.1 200 OK
Date: Thu, 21 Jan 2016 13:30:21 GMT
Server: Apache
Last-Modified: Thu, 21 Jan 2016 13:25:36 GMT
Accept-Ranges: bytes
Content-Length: 1
Cache-Control: max-age=5
Expires: Thu, 21 Jan 2016 13:30:26 GMT
Vary: Accept-Encoding
Keep-Alive: timeout=2, max=32
Connection: Keep-Alive
Content-Type: text/plain

1
disconnecting from server.

I'm not sure what you are getting at. The client does the request, completes it and disconnects. What else were you expecting?

I want the server to keep connected, since other requests will come further. the server in my code does not reconnect after it received the first request. did you get what I mean?

That is because of the while loop, once the client disconnects, it gets into an infinite loop

// do nothing forevermore:
    while (true);

You need to remove that code, and consider using a variable as switch so that the code inside !client.connected() doesn't get executed after it disconnects.

If I removed the while loop it gets "No socket available"!

Basic arduino client code that captures what is sent from a web server into a String which can be evaluated for its contents. You might try something similar.

//zoomkat 11-04-13
//simple client test
//for use with IDE 1.0.1
//with DNS, DHCP, and Host
//open serial monitor and send an e to test client GET
//for use with W5100 based ethernet shields
//remove SD card if inserted
//data from myIP server captured in readString 

#include <SPI.h>
#include <Ethernet.h>
String readString;

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

char serverName[] = "checkip.dyndns.com"; // myIP server test web page server
EthernetClient client;

//////////////////////

void setup(){

  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    while(true);
  }

  Serial.begin(9600); 
  Serial.println("client readString test 11/04/13"); // so I can keep track of what is loaded
  Serial.println("Send an e in serial monitor to test"); // what to do to test
  Serial.println();
}

void loop(){
  // check for serial input
  if (Serial.available() > 0) //if something in serial buffer
  {
    byte inChar; // sets inChar as a byte
    inChar = Serial.read(); //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
    Serial.println("connected");
    client.println("GET / HTTP/1.1"); //download text
    client.println("Host: checkip.dyndns.com");
    client.println("Connection: close");  //close 1.1 persistent connection  
    client.println(); //end of get request
  } 
  else {
    Serial.println("connection failed"); //error message if no client connect
    Serial.println();
  }

  while(client.connected() && !client.available()) delay(1); //waits for data
  while (client.connected() || client.available()) { //connected or data available
    char c = client.read(); //gets byte from ethernet buffer
    readString += c; //places captured byte in readString
  }

  //Serial.println();
  client.stop(); //stop client
  Serial.println("client disconnected.");
  Serial.println("Data from server captured in readString:");
  Serial.println();
  Serial.print(readString); //prints readString to serial monitor 
  Serial.println();  
  Serial.println();
  Serial.println("End of readString");
  Serial.println("==================");
  Serial.println();
  readString=""; //clear readString variable

}