   DEBUG_WRITETIME();
 
   // manage connection
+  unsigned long inactiveSpan = millis() - commTime;
+  
   if (clientConnected) {
-    if (client.connected()) {
+    if (inactiveSpan > DISCONN_TIME) {
+        DEBUG_PRINTLN("Disconnecting inactive client");
+        client.stop();
+        clientConnected = false;
+    } else if (client.connected()) {
       DEBUG_PRINTLN("Client is still connected");
     } else {
       client.stop();

    DEBUG_PRINT("Receiving data: ");
    boolean sendResponse = false;
    while (client.available() > 0) {
      char c = client.read();
      DEBUG_PRINTHEX(c);
      DEBUG_PRINT(" ");
  
      if (c == 0x0A) {
        sendResponse = true;
        client.flush(); // clear input buffer
        break;
      }
    }
    Serial.println();
  
    // send response
    if (sendResponse) {


// Initialize ENC28J60 Ethernet controller
void initEthernet() {
  commTime = millis();  
  Ethernet.begin(mac, ip);
  server.begin();

