The function does not work in ESP8266

I also would be add the call to led function to the while() loop:

 while (!client.available()) {
    delay(1);
  }

changing it to

while (!client.available()) {
    delay(1);
    if (flag) led_blink();
  }