I have checked the following project and similar other webservers. https://randomnerdtutorials.com/esp8266-web-server/
My main issue with this code is that there is no way to restrict where can clients connect from. A function is available client.RemoteIP() to determine the client's IP but this only seems to be possible if the client sends a valid HTTP request otherwise the code does not even go into the if (client) { // If a new client connects, section.
The problem with this if someone just telnets on the port that will BLOCK all connections for other clients (the main loop will be blocked as well) as long as his connected.
Isn't there a lower IP layer filtering possible with the ESP8266 to avoid this?
Even if there is what can be done to force anyone, to disconnect after X seconds?
The Wifihttps server provides an example for timeout:
if (millis() > timeout) {
Serial.println("timeout");
client.flush();
client.stop();
return;
}
The problem with this again that it will only be applied for valid clients not if someone connects on the port with telnet.