if the web client disconnect the web server disconnect also

hello my arduino friend
in my program I used both web client and the web server in the same program and work fine
but if the internet disconnected. normal the web client stop but my problem the web server stop also.
note : if I used the web server only in my program can work with or without internet (just from router)

but my problem the web server stop also.

Does it? Or does the code simply hang up trying to complete a GET request, waiting until the connection is restored in order to be able to receive the rest of the data?

after the web client try to connect without internet get connection failed in Serial mentor and the web server hang up and stop
and if connect the internet again must call the setup() function again to restart the web client and web sever

I suspect it is your code. I use server and client on the same sketch, and it works ok.

Thank u for your reply the server and client work for me also only if i have internet t connection only

Mine works with or without an internet connection, as long as the client is accessing localnet websites.

// this my code can try with or without internet
#include <SPI.h>
#include <Ethernet.h>
int index=0;
unsigned long lastConnectionTime = 0;
const unsigned long postingInterval = 10L * 1000L; // delay between updates, in milliseconds
// the "L" is needed to use long type numbers
byte mac[] = {0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02};
IPAddress ip(192,168,1,100); // ip in lan
IPAddress gateway(192,168,1,1); // internet access via router
IPAddress subnet(255,255,255,0); //subnet mask
//IPAddress myserver(208,104,2,86); // zoomkat web page
char myserver[] = "api.ipify.org"; // name of server
//EthernetServer server(84); //server port
EthernetClient client;
EthernetServer server(81); //server port
//EthernetClient client;
String readString;
int levelPin = A0;
//String readString;

void setup() {
// put your setup code here, to run once:

Ethernet.begin(mac);
server.begin();
Serial.begin(9600);
Serial.println("server/client 1.0 test 12/08/11"); // keep track of what is loaded
Serial.println("Send an g in serial monitor to test client"); // what to do to test client

Serial.println(Ethernet.localIP());

}

void loop() {
// check for serial input

//sendGET(); // call sendGET function
if (millis() - lastConnectionTime > postingInterval) {//**
// Serial.println(index);
// Serial.println(millis() - lastConnectionTime);
// if((millis() - lastConnectionTime)<=10002)
sendGET(); // call sendGET function
}

webServer();
}
//////////////////////////
void sendGET() //client function to send/receie GET request data.
{

if (client.connect(myserver, 80)==1) {
Serial.println("connected sendGET");
client.println("GET / HTTP/1.1"); //download text
client.println("Host:api.ipify.org");
client.println("Connection: close");
client.println();
lastConnectionTime = millis();

}
else {
Serial.println("connection failed");
Serial.println();
setup();

}

while(client.connected() && !client.available()) delay(1); //waits for data
while (client.connected() || client.available()) { //connected or data available
char c = client.read();
Serial.print(c);
}

Serial.println();
Serial.println("disconnecting.");
Serial.println("==================");
Serial.println();
client.stop();

}
void webServer(){

EthernetClient client = server.available();
int levelRead = analogRead(levelPin);
// put your main code here, to run repeatedly:
delay(1);
if(client.connected()){//*
boolean current_line_is_blank = true;
while (client.connected()) {//**
if(client.available()) {//***
char c = client.read();
if (readString.length() < 100) {

//store characters to string
readString += c;
//Serial.print(c);
}
if (c == '\n' && current_line_is_blank) {//****
// Serial.println(readString); //print to serial monitor for debuging
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("");
client.println("<meta http-equiv="refresh" content="1">");
client.println("

Home controller

");
client.println("

\n

");
//---------------------------------------------------------------------------------------
client.println("");
client.println("ON OFF Level ");
client.println("<meta http-equiv="refresh" content="2">");
// client.println("

"+levelRead+"

");
client.println( levelRead );
// Serial.println(levelRead);
//Serial.println(levelRead);
client.println("

\n

");
//-----------------------------------------------------------------------------------------
client.println("
");
client.println("
");

client.println("");
break;
}//****
if (c == '\n') {//+
// we're starting a new line
current_line_is_blank = true;
}//+
else if (c != '\r') {//++
// we've gotten a character on the current line
current_line_is_blank = false;
}//++
}//***
}//**
// give the web browser time to receive the data
delay(2000);
client.stop();
readString="";
}//*
}

The client section will fail because you require an internet connection to access api.ipify.org. It will take about 1.5 seconds to fail the connection.

I'm not even going to try your code. You use the String data type, and it has never failed to crash my sketches.

yes i need about about 1.5 seconds to fail the connection. during this time the web server down

fayez2876s:
yes i need about about 1.5 seconds to fail the connection. during this time the web server down

That is correct.

edit: You can shorten that to 200ms if you set the retransmission count on the w5100.

i set the time but when disconnected the web server stop

You must be more specific. When which disconnects? If you mean the client connection returning a fail, mine does not stop the server. Well, except for the 1.5 seconds the client takes to fail.