Re: Chrome saying ERR_INVALID_HTTP_RESPONSE when using port
Posted: Sat Jan 07, 2017 12:35 am
Thanks! Pointed me in the right direction. See below for examples that work & don't work when listening on port 81. I still have some more testing to do but I presume Chrome is demanding it sees the response code "HTTP/1.0 200 OK" and I was not sending it...
The link you provided works fine on port 81 ie. This webserver code works:
-- a simple HTTP server
srv = net.createServer(net.TCP)
srv:listen(81, function(conn)
conn:on("receive", function(sck, payload)
print(payload)
sck:send("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<h1> Hello, NodeMCU.</h1>")
end)
conn:on("sent", function(sck) sck:close() end)
end)
But this code does NOT work when listening on port 81. It is from the NodeMCU net.createserver documentation and is what I based my code on haha
-- server listens on 81, if data received, print data to console and send "hello world" back to caller
-- 30s time out for a inactive client
sv = net.createServer(net.TCP, 30)
function receiver(sck, data)
print(data)
sck:close()
end
if sv then
sv:listen(81, function(conn)
conn:on("receive", receiver)
conn:send("hello world")
end)
end
The link you provided works fine on port 81 ie. This webserver code works:
-- a simple HTTP server
srv = net.createServer(net.TCP)
srv:listen(81, function(conn)
conn:on("receive", function(sck, payload)
print(payload)
sck:send("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<h1> Hello, NodeMCU.</h1>")
end)
conn:on("sent", function(sck) sck:close() end)
end)
But this code does NOT work when listening on port 81. It is from the NodeMCU net.createserver documentation and is what I based my code on haha
-- server listens on 81, if data received, print data to console and send "hello world" back to caller
-- 30s time out for a inactive client
sv = net.createServer(net.TCP, 30)
function receiver(sck, data)
print(data)
sck:close()
end
if sv then
sv:listen(81, function(conn)
conn:on("receive", receiver)
conn:send("hello world")
end)
end