Migration from 3.x to 4.0
Introduction
This is a guide to highlight breaking changes in the API to help the migration of projects from versions 3.X to version 4.0 of the Arduino ESP32 core.
WebServer
Server-Sent Events (SSE) state moved from the client to the server
The SSE hold marker is a directive to the server (“do not close this connection”), not a property of the TCP socket, so it is now owned by
WebServer instead of NetworkClient. The marker is reset for every new connection and is independent of which client wrapper is used
to reach the connection.
Deprecated APIs (still functional, removal planned for 5.0)
NetworkClient::setSSE— useWebServer::enableSSE()instead.NetworkClient::isSSE— useWebServer::isSSE()instead. Note thatNetworkClient::isSSE()only reflects the legacy marker, whileWebServer::isSSE()reflects both.
New APIs
WebServer::enableSSE— call it from the request handler to keep the connection open as an SSE stream (replacesserver.client().setSSE(true)).WebServer::isSSE— query whether the current connection is a held SSE stream (replacesserver.client().isSSE()).
Migration example
// 3.x
server.on("/events", HTTP_GET, []() {
server.client().setSSE(true);
server.setContentLength(CONTENT_LENGTH_UNKNOWN);
server.send(200, "text/event-stream", "");
// then push "data: ...\n\n" lines from loop() via server.client()
});
// 4.0
server.on("/events", HTTP_GET, []() {
server.enableSSE();
server.setContentLength(CONTENT_LENGTH_UNKNOWN);
server.send(200, "text/event-stream", "");
// then push "data: ...\n\n" lines from loop() via server.client()
});