Adding a countdown timer when checking for an Ethernet client

I'm using something very similar to the WebServer example when using an Ethernet shield. I'm trying to add a countdown timer to my program so that when a "client" has connected to my Ethernet shield so I can effectively kick them off or shut things down when they have been connected for over 5 minutes. This will also allow my Arduino to power external items down when the "client" has left and I have no more people connected to my Ethernet shield.

Below is the WebServer example code. When I add a simple incremental loop (timer = timer + 1) to my program, it never gets beyond 1 or 2. I added this to the spot in the code when the client is available. I'm guessing the part of the code that is listening for incoming clients is causing my Arduino code to stop processing at that point while it is listening. Correct? In essence, I want to know how can I also add a countdown timer in the background?

void loop()
{
  // listen for incoming clients
  Client client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();

          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(analogRead(analogChannel));
            client.println("
");
          }
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } 
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
  }
}

I added this to the spot in the code when the client is available.

The client.available() function is similar to the Serial.available() function, in that it returns a non-zero value when the client has unread data available. Putting a "timer" here is not a smart place to put it.

The client.connected() function returns true when a client connects. Use millis() to record when this happens.

If the same client is still connected some time later, you can boot them off.

In essence, I want to know how can I also add a countdown timer in the background?

There is no foreground/background processing on the Arduino. There is only one process space. It isn't clear exactly what you want to do. When a client connects to your server, the server generates a response and ends the connection to the client.

There are no long term connections to be terminated after 5 minutes.

The Arduino can "power external items" as easily when there are clients connected as when there are no clients connected.

PaulS:
The client.connected() function returns true when a client connects. Use millis() to record when this happens.

If the same client is still connected some time later, you can boot them off.

This is the part I'm having trouble with. Exactly how might one do this?

This is the part I'm having trouble with. Exactly how might one do this?

You seem to want a web server based connection, which by design are not normally persistant. Normally a client connects with a web server, the web server takes the info from the client and processes the info, then returns info the the client, and closes the connection. You seem to want to ban someone that is making multiple connections to the server beyond some number.

So what happens to the processing of my sketch when the Arduino is waiting for a client to connect? Is it repeatedly checking for the connection (from the loop function), or is it simply paused waiting for the connection status to be TRUE?

So what happens to the processing of my sketch when the Arduino is waiting for a client to connect? Is it repeatedly checking for the connection (from the loop function), or is it simply paused waiting for the connection status to be TRUE?

What happens in my code, which I won't show you, when...

You are the only one that can answer that question. Typically, you have a "if(client.connected())" block that handles the connection by a client. What you do outside of that block is something only you know.