ESP8266 Webserver Project

Moderator: Sprite_tm

User avatar
By Sprite_tm
#40754 Also, the 'disconnect after a few seconds of inactivity' probably is a SDK thing. I'll see if I can change that.

Edit: Just committed some code. For the nonos SDK, the websocket TCP sockets should now have a timeout of 2 hours.
User avatar
By dbetz
#46724 First, thanks for a very useful library!!

I've just started using esp-httpd and am running into an error running the WebSockets test. If I run it from Safari, I get the error:

WebSocket connection to 'ws://10.0.1.3/websocket/ws.cgi' failed: Error during WebSocket handshake: 'Connection' header value is not 'Upgrade'


Does anyone know what would cause that? Is there any special setup needed to run the test?

Thanks!
David
User avatar
By dbetz
#46860
Sprite_tm wrote:That sounds like a bug. Can you get the data that's sent back and forth somehow? (Wireshark, dev console equivalent in Safari, ...)?

I figured out what was going wrong. The problem is, httpdStartResponse always inserts "Connection: close" into the header. Then, the WebSockets code adds "Connection: Upgrade" but Safari must just see the first "Connection" header. I added code to explicitly check for code==101 and that seemed to fix the problem although I don't think it's a very clean solution:
Code: Select all//Start the response headers.
void ICACHE_FLASH_ATTR httpdStartResponse(HttpdConnData *conn, int code) {
   char buff[256];
   int l;
   l=sprintf(buff, "HTTP/1.%d %d OK\r\nServer: esp8266-httpd/"HTTPDVER"\r\n",
         (conn->priv->flags&HFL_HTTP11)?1:0,
         code);
   httpdSend(conn, buff, l);
    if (code != 101) {
       l=sprintf(buff, "%s\r\n",
             (conn->priv->flags&HFL_CHUNKED)?"Transfer-Encoding: chunked":"Connection: close");
       httpdSend(conn, buff, l);
    }
}
Last edited by dbetz on Wed May 04, 2016 11:42 am, edited 1 time in total.