web client sketch posted by SurferTim fails to connect

I use the Ethernet Arduino, and have modified surferTim's Web server sketch into a simple webserver that allows me to monitor some temperatures in and outside my house, and remotely start up the central heating when I am abroad for a time.
This works fine, so I have the basic connectivity going.

A problem that I foresee, is that if power goes down, and stays down for a while, I may be given a different external ip number by my provider when power returns, and I will not be able to reach my server anymore until I get home and find out what the new ip number is. To solve this I want my server to retrieve its external ip number from http://checkip.dyndns.com/ upon each reboot, and mail it to me. To find out how I should retrieve the ip number from the dyndns website I tried to use surferTim's web client using the get method, posted on the Arduino website/learning. To start, I just changed the mac address and IP adress lines in the example into those of my own server, leaving the server to be approached at google. The only response I get is connecting ..... Fail n, with n increasing. What might be wrong ? I will be most grateful for an answer.

Post your code. The setup you want will use server and client code in the same sketch. I have done that.

Some client test code to get the WAN IP address. Something simpler might be to use a dynamic IP service like no-ip.com or similar services.

//zoomkat 3-1-13
//simple client checkip test
//for use with IDE 1.0.1 or later
//with DNS, DHCP, and Host
//open serial monitor and send an e to test
//for use with W5100 based ethernet shields

#include <SPI.h>
#include <Ethernet.h>

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

char serverName[] = "checkip.dyndns.com"; // 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("Better client ip test 3/1/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
}

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.0"); //download text
    client.println("Host: checkip.dyndns.com");
    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
    Serial.print(c); //prints byte to serial monitor 
  }

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

}

thanks to both of you for your answers. I am travelling now, and have no access to my code and Arduino board. Thursday I will get back to you on this, and send the code.

Apologies for this late response. The forum does presently not work with internet explorer. Now I have sent this thru my girlfriends' android tablet. Below this is my present code. I separately tested zoomkat's webclient and found it works well. I will integrate that into my code. I have not found out yet how I can mail the resulting ip address to myself. About my-ip.com or others like that, I think these are paid services. Also I do not understand how such a service would find my new ip adress if my provider changed it.

In the present code I also wanted to add some password security, to prevent other people from fiddling with my central heater, but I think that what I have done now is rather flimsy, especially as the browser displays my password. Is there any experience with https on the Arduino ?

/*
Web server sketch for IDE v1.0.1 and w5100/w5200
Posted October 2012 by SurferTim
Modified proron.40@gmail.com 7.11.2013
*/

#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>

int CountWrongPwd=-1;
int CountWrongPwdTotal=-1;

// this must be unique, its Ron's Arduino ethernet board
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x72, 0x7E };

// change to your network settings Ron's UPC network
IPAddress ip( 192,168,0,10 );
IPAddress gateway( 192,168,0,1 );
IPAddress subnet( 255,255,255,0 );

//Create a server that listens for incoming connections on the specified port.
EthernetServer server(82);

void setup()
{
Serial.begin(9600);
analogReference(EXTERNAL);

pinMode(7,OUTPUT);
digitalWrite(7,LOW);
pinMode(10,OUTPUT);
digitalWrite(10,HIGH);
// Serial.print("Starting SD..");
// if(!SD.begin(4)) Serial.println("failed");
// else Serial.println("ok");

//Initializes the ethernet library and network settings
Ethernet.begin(mac, ip, gateway, gateway, subnet);
// digitalWrite(10,HIGH);

delay(2000);
server.begin();
//Serial.println("Ready");
}

void loop()
{

EthernetClient client = server.available();
if(client)
{
boolean currentLineIsBlank = true;
boolean currentLineIsGet = true;
int tCount = 0;
char tBuf[64];
char *pch1 = "wrong";
char *pch2 = "wrongwrong";
//Serial.print("Client request: ");

while (client.connected()) {
while(client.available()) {
char c = client.read();

if(currentLineIsGet && tCount < 63)
{
tBuf[tCount] = c;
tCount++;
tBuf[tCount] = 0;
}

if (c == '\n' && currentLineIsBlank)
{
// send a standard http response
//Serial.println(tBuf);
//Serial.print("POST data: ");
while(client.available()) Serial.write(client.read());
//Serial.println();
pch1 = strtok(tBuf,"?");
pch1 = strtok(NULL,"=");
pch2 = strtok(NULL," ");

//Serial.println(pch1);
//Serial.println(pch2);
//Serial.println("Sending response");

client.write("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n");

if((strncmp(pch1,"xxx",3) == 0)&(strncmp(pch2,"yy",2) == 0))
{//pch2=on
digitalWrite(7,HIGH);
delay(10000);
digitalWrite(7,LOW);
}//pch2=on

if((strncmp(pch1,"zzz",3) == 0)&(strncmp(pch2,"qqqqqqqqqq",10) == 0))
{

client.write("

Ron's Arduino Webserver v5.106d !

");

//start of table

// after calling analogReference(EXTERNAL)
//connecting Aref with +5 via 4k3
//with 2k2 in series with KTY10-7 sensor

client.write("

");
client.write("<table border=1 bgcolor='white'");
client.write("width=180 height=30 ALIGN=right>");
client.write("");
client.write("");
client.write("Outside
temperature
C");
client.write("");
client.write("");
client.write("Workshop
temperature
C");
client.write("");
client.write("");
client.write("Living
temperature
C");
client.write("");
client.write("");
client.write("");
client.write("");
client.print(float(analogRead(1))*0.476 - 236.0,1);
client.write("");
client.write("");
client.print(float(analogRead(0))*0.464 - 231.0,1);
client.write("");
client.write("");
client.print(float(analogRead(2))*0.476 - 236.0,1);
client.write("");
client.write("");
client.write("
");

// button set.

client.write("
");
client.write("
");

client.write("Number of failed login attempts : ");
client.println(CountWrongPwdTotal);
CountWrongPwd=-1;
CountWrongPwdTotal=-1;
client.write("\r\n\r\n");
client.stop();
}
else
{
//Serial.println("no");
client.write("

Ron's Arduino webserver ?

");
client.write("Password:

");
CountWrongPwd++;
CountWrongPwdTotal++;
// Serial.println(CountWrongPwd);
if(CountWrongPwd>2)
{
client.write("Wrong password. Website is locked");
CountWrongPwd=-1;
client.write("\r\n\r\n");
client.stop();
delay(60000);
}
else
{
client.write("\r\n\r\n");
client.stop();
}

}

}
else if (c == '\n')
{
currentLineIsBlank = true;
currentLineIsGet = false;
}
else if (c != '\r')
{
currentLineIsBlank = false;
}
}
}
//Serial.println("done");
}
}

That is code was originally written before the F() function. That code was modified in September to use that to reduce the SRAM use.
http://playground.arduino.cc/Code/WebClient
Every static string uses the F() function to keep that string in program memory. You may be running out of SRAM.

About my-ip.com or others like that, I think these are paid services. Also I do not understand how such a service would find my new ip adress if my provider changed it.

If you are serious about remote home control, then use one of the dynamic IP services which can be used with your router. Makes things much easier (I read that a FOSCAM camera includes a dynamic IP service feature). As to a password setup, in the short term you could use a web form with a text box to send commands that would be tough to hack (like poronheat72 to set the thermostat to 72 deg.).