ESP8266 to ESP8266 communication using Arduino IDE
I don't like the order between two statements:

server.begin();
...
WiFi.config(ip,gateway,subnet);


Since you start the server and then modify the IP address, server may be "connected" to the wrong address. Try swapping these two statement groups - start the server after setting the IP address.

I don't know your WiFi router, but it might not like you arbitrarily changing your IP address like that.