Ethernet Commands Stop Working?

Hello,

I have programmed this very basic button command for a web server. The problem is that after about a minute or less the commands stop working. If I reload the program it works right away. Why would this happen? Thanks for the help!

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char server[] = "192.168.1.157";
IPAddress ip(192,168,1,177);

Button button1 = Button(31,PULLUP);
Button button2 = Button(32,PULLUP);
EthernetClient client;

void setup() {
Ethernet.begin(mac, ip);
Serial.begin(9600);
delay(1000);
pinMode(7,OUTPUT); //debug to led 13
Serial.println("connecting...");
client.connect(server, 8088);
}
void loop() {
if(button1.isPressed()){
digitalWrite(7,HIGH);
Serial.println("This command worked!");
digitalWrite(7,LOW);
Serial.println("connected");
client.println("GET /api/?Function=SetFader&Value=20 HTTP/1.0");
client.println();
}
if(button2.isPressed()){
digitalWrite(7,HIGH);
Serial.println("So did this one!");
digitalWrite(7,LOW);
Serial.println("connected");
client.println("GET /api/?Function=SetFader&Value=190 HTTP/1.0");
client.println();
}
else {
Serial.println("Waiting for input");

}
}

You are assuming that once a connection is made, it is persistent. It is NOT. The connection exists only long enough to send a GET request and collect the response. Once the server responds, it closes the connection. Once the client reads the response, if can close the connection on its end. Only after the connection is closed on both ends is the socket available for reuse. Since there are only 4 sockets, your code will quickly run out of connections.

Read the response from the server, or don't make a request.

That's really good info!

So what would the remedy be for that? Do I need to write some code for each sucessfull GET request that closes the connection or reads the reply?

Here is my web client example code. It sends a request and downloads the contents of a webpage every 30 seconds.
http://playground.arduino.cc/Code/WebClient
You may borrow what you want from it. It has a timeout feature that keeps the code from freezing if the connection is broken or the server stalls.

I will check it out.

Maybe my understanding of how ethernet connections work is not correct.

I am trying to write some code for a hardware controller that triggers an HTTP API that will have different buttons send out different https requests. I am not interested in the response, but simply that the http request is sent. The hardware will be making upwards of 30+ requests per minute and it it crucial that the time from pressing a button to the time that the http request is made is almost instantaneous.

What is the best way to setup a connection like that? Does a connection need to be made and then closed each time a request is sent? I have the code working now but it stops working in less than a minute. I was able to get the HTML response printed but it is still stopping after a while.

Another thing to note is that I get the following response from the web server that I am triggering.

HTTP/1.1 200 OK
Content-Length: 32
Content-Type: text/html; charset=utf-8
Cache-Control: no-cache
Connection: Keep-Alive

Function completed successfully.

When it says "Connection: Keep-Alive" does that mean each time that I make this request it is taking up an available connection so that all the connections end up being used?

My personal preference is UDP. No connection to maintain. The "client" sends a packet to the "server" and the "server" responds with a packet.