- I wanted to allow only one client at a time. i.e.. If I open http://ip:port in browser so client connected to ESP now no more browser can connect to esp until running tab close or browser close.
- Here is i have attached code of sample server.
Code: Select all
#include <stdio.h>
#include "esp_err.h"
#include "esp_event.h"
#include "esp_http_server.h"
static esp_err_t hello_get_handler(httpd_req_t *req) {
const char* response = "Hello, ESP32 HTTP Server!";
httpd_resp_send(req, response, strlen(response));
return ESP_OK;
}
void app_main(void) {
httpd_config_t config = HTTPD_DEFAULT_CONFIG();
httpd_handle_t server = NULL;
// Start the server
if (httpd_start(&server, &config) == ESP_OK) {
// Set URI handlers
httpd_uri_t hello = {
.uri = "/hello",
.method = HTTP_GET,
.handler = hello_get_handler,
.user_ctx = NULL
};
httpd_register_uri_handler(server, &hello);
}
}