From 52150c2cd26feb2120e0c7e73d1f8c231293fb32 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Fri, 19 Jun 2020 08:20:33 +0200 Subject: [PATCH] http_server example: WebSocket server to set final flag in async messages Closes https://github.com/espressif/esp-idf/issues/5405 --- examples/protocols/http_server/ws_echo_server/README.md | 1 + .../protocols/http_server/ws_echo_server/main/ws_echo_server.c | 1 + 2 files changed, 2 insertions(+) diff --git a/examples/protocols/http_server/ws_echo_server/README.md b/examples/protocols/http_server/ws_echo_server/README.md index 61bcc0fbbd..2d330be4d9 100644 --- a/examples/protocols/http_server/ws_echo_server/README.md +++ b/examples/protocols/http_server/ws_echo_server/README.md @@ -10,6 +10,7 @@ ws_server_example_test.py could be used as a simple WS client). The server registers WebSocket handler which echoes back the received WebSocket frame. It also demonstrates use of asynchronous send, which is triggered on reception of a certain message. +Please note that the WebSocket HTTPD server does not automatically fragment messages, so the application code must deal with fragmentation, setting `final` flag as appropriate. Single (complete/unfragmented) WebSocket frames must have the `FIN` flag set to be accepted as valid (see [RFC6455, section 5.4](https://tools.ietf.org/html/rfc6455#section-5.4)). ### Hardware Required diff --git a/examples/protocols/http_server/ws_echo_server/main/ws_echo_server.c b/examples/protocols/http_server/ws_echo_server/main/ws_echo_server.c index e10b0ba606..cab642101b 100644 --- a/examples/protocols/http_server/ws_echo_server/main/ws_echo_server.c +++ b/examples/protocols/http_server/ws_echo_server/main/ws_echo_server.c @@ -48,6 +48,7 @@ static void ws_async_send(void *arg) ws_pkt.payload = (uint8_t*)data; ws_pkt.len = strlen(data); ws_pkt.type = HTTPD_WS_TYPE_TEXT; + ws_pkt.final = true; httpd_ws_send_frame_async(hd, fd, &ws_pkt); free(resp_arg);