Problem with reconnecting to the server

Hi,

I’m using following functions for connecting and reconnecting my arduino galieleo to server.

int initEth(){  
  Serial.println("Initializing ethernet..");
  while (Ethernet.begin(macAddr) == 0){
    delay(10000); //wait for 10sec and try again to get the address from DHCP
    Serial.println("Faild to configure Ethernet using DHCP");
    Ethernet.begin(macAddr);
  }
  delay(3000);  
  Serial.println("Ethernet Initialized successfully"); 
  
  //print retrieved IP address from DHCP
  Serial.print("Retreived IP addr: ");
  for (byte thisByte = 0; thisByte < 4; thisByte++){
    Serial.print(Ethernet.localIP()[thisByte],DEC);
    Serial.print(".");
  }  
  Serial.println();
  return 1;
}

int connectToServer(){
  uint8_t numberOfChecks = 0;
  if (Ethernet.begin(macAddr)==0){
    initEth();
    delay(5000);
  }  
  Serial.println("Connecting to server..");
//  int conn = client.connect(serverAddr,portOnServer);
  int conn = 0;
  while(!conn){
    Serial.print("Connection to the server FAILED with error: ");
    Serial.print(conn);
    Serial.println(", retrying..");

    if (numberOfChecks>5) {
      delay(3000);      
      numberOfChecks = 0;
      Serial.println("Renewing lease from the DHCP server");
      initEth();      
    }
    
    delay(3000);    
    conn = client.connect(serverAddr,portOnServer);
    numberOfChecks++;
  }    
  Serial.println("Connection to the server successful");
  delay(1000);

  client.flush(); 
}

When program starts, connection works perfectly, but when I initiate reconnection process I’m unable to reconnect to the server. Funny thing is when I unplug the ethernet cable and initEth function is called I get the same IP address as last one.

Does anyone knows a way how to solve this issues?