Using the ethernet shield to polling a URL

the subject more or less says what i'm trying to do :) i'd like to download a file every minute so in effect just poll the URL using a delay.

i've got everything setup so the ethernet shield will download a file however i can only get it to work for the first request.

it seems that when trying to use client.connect() a second time it bombs out. i've tried all sorts of things of tweaks to the example code provided for the Client class. what i'd probably like to do is just put everything in the loop function (declaration and initialisation of the client variable, then read all data, then stop the client all in one loop pass) and i've tried this but to no avail.

has anyone done anything along these lines? is there something obvious i'm missing as to why this won't work?

many thanks.

Can you post your code? The example only shows client.connect() being called once in setup.

sure… this is the sample code:

#include <Ethernet.h>

byte mac = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip = {
169, 254, 205, 205 };
byte gateway = {
169, 254, 241, 235 };
byte subnet = {
255, 255, 0, 0 };
byte server = {
169, 254, 241, 235};

void setup() {
Ethernet.begin(mac, ip, gateway, subnet);

void loop()
Serial.println(“in loop”);

Client client = Client(server, 80);


if (client.connect()) {
client.println(“GET /~colm/test.txt HTTP/1.0”);
} else {
Serial.println(“error connecting”);


while (client.available()) {
char c =;
Serial.println(“finished reading”);

if (!client.connected()) {

Serial.println(“end loop”);


and this is what i’m seeing on the serial monitor:

in loop
HTTP/1.1 200 OK
Date: Tue, 17 Mar 2009 08:04:35 GMT
Server: Apache/2.2.9 (Unix) mod_ssl/2.2.9 OpenSSL/0.9.7l DAV/2
Last-Modified: Tue, 17 Mar 2009 08:04:14 GMT
ETag: “60f681-d-4654c034adb80”
Accept-Ranges: bytes
Content-Length: 13
Connection: close
Content-Type: text/plain

hello world.
finished reading

end loop
in loop

What version of the IDE are you using? This sounds like a known issue that was intended to solved with 0013 but wasn’t, but I think has now actually been solved in 0014.


wow, fantastic, that did the trick!

i’m new around here (just did an arduino beginner’s workshop with the wonderful guys a few weeks ago in london) but lesson learned is to keep an eye for new releases :slight_smile:

many many thanks!