ESP8266 Webserver Project

Moderator: Sprite_tm

User avatar
By Sprite_tm
#14407 Ovaltino: Ahh, that sounds somewhat feasible... although it's actually a bug on the webclient part as far as I can see: esphttpd advertises itself as a HTTP/1.0 server, and the standard behaviour of that should be assumed to close the connection unless both the client and the server send a 'Connection: keepalive' over the line. Also, closing a socket or leaving it open shouldn't have any effect on the ESP re-associating with the access point.

Just so I can test it: What browser are you using?
User avatar
By Ovaltineo
#14463 I think you are right. I removed the "Connection: close" headers and it still works. I found that I was getting reconnect errors when the ESP (running on 3XAA batteries) is connected to my laptop for serial output debugging. Once I disconnect and let it run on its own, it works fine with or without the "Connection: close" header.
User avatar
By David Zhou
#21782 I have the same issue and need a work around. Could you show me how and where to add Connection:close?
Thanks.


David
Ovaltineo wrote:Good news! I can now get it working at any place in my house. I added "Connection: close" header in all responses and I don't get reconnect errors anymore, especially in the home page where multiple resources (css and jpgs) are present in the page.

I examined the esphttpd code and noticed that the socket is being closed after a http response is sent. This works via AP mode because there is minimal propagation delay and the the browser client sees the socket has been closed before it has a chance to make another request on the same socket. In STATION mode, there is more propagation delay and the client has already made another request on the socket before it sees the close on the socket. This causes the ESP to reconnect the socket (doesn't really work) and causes havoc. By adding "Connection: close" to the response header, the client browser is forced to close the socket and open a new one for each request.

So, I was right in my original post, esphttpd is closing the socket too early.