Page 1 of 1

WebServer.h how do i know if a client disconnects?

Posted: Sun Mar 17, 2024 8:32 am
by PepeTheGreat
My video streaming app does use server.sendContent(); to stream mjpeg pictures. This is done in a loop inside the webserver handler. This loop continues to send even if the client disconnects. How do i prevent this?

Using "WiFiServer" there is client.available() and client.connected() to check this.

Using "esp_http_server.h" the httpd_resp_send_chunk function gives the return ESP_OK on sucess.

How do i replicate this functionality with "WebServer.h"?
Or can i make the OTA updater functional with "WiFiServer" or "esp_http_server.h" ?

Re: WebServer.h how do i know if a client disconnects?

Posted: Sun Mar 17, 2024 7:25 pm
by lbernstone
I am not so familiar with the code to have a quick answer for you, but the WiFiClient that WebServer is using is public, so in theory you should be able to look at that object to see if it is connected.
As far as an IDF-based wifi manager, esp-wifi-manager can be included in a project as a component.

Re: WebServer.h how do i know if a client disconnects?

Posted: Mon Mar 18, 2024 1:52 pm
by PepeTheGreat
lbernstone wrote:
Sun Mar 17, 2024 7:25 pm
the WiFiClient that WebServer is using is public, so in theory you should be able to look at that object to see if it is connected.

TY. That might exceed my talent. Will try.

Project:
http video:
https://youtu.be/NCWrQaDqzJg
external video:
https://youtube.com/shorts/Xo_1b1SBKy8

Re: WebServer.h how do i know if a client disconnects?

Posted: Mon Mar 18, 2024 7:39 pm
by lbernstone

Code: Select all

#include <WebServer.h>

WebServer server(80);

void handleRoot() {
  WiFiClient wfc = server.client();
  if (wfc.connected()) {
    Serial.print("Remote IP: ");
    Serial.println(wfc.remoteIP());
  }
  server.send(200, "text/plain", "Hello!\n");
}

void setup() {
  Serial.begin(115200);
  WiFi.begin("larryb","clownfish");
  WiFi.waitForConnectResult();
  Serial.println(WiFi.localIP());
  server.on("/", HTTP_ANY, [](){handleRoot();});
  server.begin();
}

void loop() {
  server.handleClient();
  delay(100);
}

Re: WebServer.h how do i know if a client disconnects?

Posted: Mon Mar 18, 2024 9:11 pm
by PepeTheGreat
👍 👍 👍

Code: Select all

  while(wfc.connected())
  {
Works perfectly. TY

Next thing is mounting esp32cam on this: