   }
 
   if (!clientConnected) {
+    // connection is considered to be established only when data are received
     client = server.available();
     if (client) {
-      client.flush();
       clientConnected = true;
       Serial.println("New client is connected");
     } else {

EthernetServer server = EthernetServer(TCP_PORT);
EthernetClient client;
boolean clientConnected = false;
byte response[RESPONSE_LEN] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06};

// Speed control
unsigned long time;


#define DHT_TYPE      DHT22 // DHT 22
#define ONE_WIRE_CNT  3     // count of 1-wire connections
#define TCP_PORT      502   // Modbus TCP default port
#define RESPONSE_LEN  29    // length of Modbus TCP response

// DHT instance
DHT dht(DHT_PIN, DHT_TYPE);
