I love the ESP8266WebServer library for its callbacks. It works great with browsers (port 80), which e.g. send: "GET /function HTTP/1.1 " plus a bunch of additional data. The callback is called within fractions of a second. Though, when I construct a client which connects to another port (50002) sends "GET /function HTTP/1.1 " and no other data, the ESP8266WebServer library callback takes over half a minute to execute. I wonder whether there is anyone around which can explain me why this is.
By the way, when I use WifiServer for the same (no callbacks though) everything works perfect. Just as a last tidbit: under the hood ESP8266WebServer is using WifiServer.. ![]()
80 is the default port for HTTP; a GET would not have "data", but a browser is likely to send several headers along with the initial request-line.
The behavior on another port like 50002 is easy enough to test in the browser, by adding it to the URL. For example, instead of 192.168.1.2/function, it would be 192.168.1.2:50002/function If the server responds normally/quickly then the problem is with the client request, not the server.
With HTTP/1.1, you must also specify a Host header (although this may not be strictly enforced). With Arduino clients, it is also common to request Connection: close -- ESP8266WebServer only supports one connection at a time anyway. So a client sending "no other data" is likely wrong to some degree.
You can skip both of those by requesting HTTP/1.0 instead, as long as the server supports it. Then the minimum request is
- method/verb, e.g.
GET - space
- URI-path starting with slash:
/function - space
HTTP/1.0- carriage return and line feed to end the request-line
- another CR+LF for a blank line to end the headers (there were none)
@kenb4 - THANKS A LOT! adding a blank and a second CRLF solved it...!