As the title says... Chat on...

User avatar
By JOHN_T
#60418 Hi Everyone. I have a simple webserver running on NodeMCU listening on TCP port 80 and web browsers can connect fine. When I change the webserver listening TCP port to 81, Chrome web browser (both on Windows & Android) returns an error page with "ERR_INVALID_HTTP_RESPONSE". I think it's something to do with Chrome forcing webservers to migrate to HTTPS... and I need to use multiple ESP8266 devices listening on different TCP ports eg. 81, 82, 83 etc.

Sample code:
srv=net.createServer(net.TCP)
srv:listen(81,function(conn)
conn:on("receive", function(client,request)
local buf = ""
local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP")
if(method == nil)then
_, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP")
end
local _GET = {}
if (vars ~= nil)then
for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do
_GET[k] = v
end
end
...and then I fill the buffer and send response...
client:send(buf);
client:close();
collectgarbage();
end)
end)



Internet Explorer and my phone's built-in browser app "Internet" both work fine when connecting to port 81, it's just Chrome that won't display the page when connecting to other than port 80.

Anyone have any ideas on how NodeMCU can respond correctly to Chrome browser on other than port 80?
User avatar
By JOHN_T
#60515 This is not the cure. I changed Chrome shortcut to have "--explicitly-allowed-ports=81,84,87" but Chrome still gives the same "ERR_INVALID_HTTP_RESPONSE" message when I browse to NodeMCU URL http://10.1.1.243:81 This was using Chrome on Windows10 desktop, I don't know how to change the shortcut on Chrome Android app...

I modified my webserver (IIS on Windows Server 2003) to listen on port 81 and when I browse to it in Chrome using URL http://10.1.1.240:81 it works perfectly fine. I remove the "--explicitly-allowed-ports=81,84,87" from Chrome shortcut and Chrome still works perfectly fine. Webserver listening on port 81 also displays fine on Chrome Android app.

This leads me to the conclusion that Chrome will by default successfully render web pages on non-standard ports without modification. Chrome still will not work with with NodeMCU on non-standard ports combination.

This kinda points to NodeMCU not responding with what Chrome is expecting. I have absolutely no idea what Chrome is expecting to see on a non-standard port.
User avatar
By marcelstoer
#60524
JOHN_T wrote:...and then I fill the buffer and send response...


It might be relevant what this buffer contains i.e. what exactly you're sending back to the browser...

Start small to reduce complexity and thus reduce the number of things that can potentially go wrong. What happens if you use the trivial NodeMCU example from https://github.com/nodemcu/nodemcu-firm ... ming-model and change the port to 81?