You may run into some issues when using the ESP8266's advanced functions. We will list some of the common problems that many people face and some ways of troubleshooting them.
There are three scenarios in which this could happen:
The ESP8266 board has not successfully connected to the Wi-Fi network
The firewall is blocking your Arduino IDE from accessing the OTA port
The Arduino IDE needs a restart
To solve the issue, start by restarting the Arduino IDE. If that does not work, troubleshoot the first scenario by checking whether the ESP8266 IP address was displayed on the serial monitor after uploading the OTA code. If it wasn't, check the Wi-Fi credentials in your sketch and make sure they are correct.
If all that does not work, try changing the firewall settings on your computer, so that it allows the Arduino IDE to access Wi-Fi network features.