Page 1 of 1

Two HTTPS servers on one ESP32?

Posted: Thu Mar 10, 2022 10:35 pm
by tpbedford
I'm certainly approaching this the wrong way, but I'd like to have an HTTPS server and WSS (secure websocket) server running on one ESP32.

I've tried to run the ESP-IDF Simple https server example and the ESP-IDF wss_server example in parallel, calling both:

Code: Select all

start_wss_echo_server()
and

Code: Select all

start_webserver()
both of which ultimately call

Code: Select all

httpd_ssl_start(&server, &conf);
I've configured them to listen on different ports (and use a differnt UDP ctrl_port), and both appear to start up OK, but neither actually accept a connection on their respective ports (which are 8443 and 443).

I presume I can just use on instance of httpd_ssl_start() and bind both my https server and wss server on different URLS?

Anyone able to provide suggestions on setting this up?

Re: Two HTTPS servers on one ESP32?

Posted: Fri Mar 11, 2022 2:34 am
by chegewara
Hi,
this may or may not be useful to you. In this example i am running 1 x http server + 1 x ws server + 1 x https server + 1 x wss server, all at the same time:
https://github.com/chegewara/esp32sx-c- ... ttp-server

It may be useless to you because it is based on C++ components/wrappers, but you may test with it and eventually see how it works.

Re: Two HTTPS servers on one ESP32?

Posted: Fri Mar 11, 2022 2:35 am
by ESP_YJM
Do you make two server ctrl_port different?

Re: Two HTTPS servers on one ESP32?

Posted: Mon Mar 14, 2022 4:14 am
by tpbedford
ESP_YJM wrote:
Fri Mar 11, 2022 2:35 am
Do you make two server ctrl_port different?
I did make ctrl_port different.

I was unable to get this to work. For my application it was simple enough that I could bind the Websocket handler to "/ws" and move the http fileserver from "/*" to "/a/*" to avoid a conflict in the wildcard .

So I made the websocket server dependent on the httpd instance instead.

chegewara wrote:
Fri Mar 11, 2022 2:34 am
Hi,
this may or may not be useful to you. In this example i am running 1 x http server + 1 x ws server + 1 x https server + 1 x wss server, all at the same time:
https://github.com/chegewara/esp32sx-c- ... ttp-server

It may be useless to you because it is based on C++ components/wrappers, but you may test with it and eventually see how it works.
Actually it looks like the same solution as mine: Bind another path/handler to the one httpd instance:
  1.     ssl_server.registerPath("/", request_handler_ssl);
  2.     ssl_server.registerPath("/ws", wss_request_handler, HTTP_GET, true);
Basically this is how I did it in mine.

Re: Two HTTPS servers on one ESP32?

Posted: Tue Mar 15, 2022 8:26 am
by ESP_YJM
Could you please change the log level to debug and share your whole log.

Re: Two HTTPS servers on one ESP32?

Posted: Fri Nov 03, 2023 10:47 pm
by greycon
chegewara wrote:
Fri Mar 11, 2022 2:34 am
Hi,
this may or may not be useful to you. In this example i am running 1 x http server + 1 x ws server + 1 x https server + 1 x wss server, all at the same time:
https://github.com/chegewara/esp32sx-c- ... ttp-server

It may be useless to you because it is based on C++ components/wrappers, but you may test with it and eventually see how it works.
That's a nice piece of work - so if I understand it at a first read, you manage to achieve some actual asynchronous request processing by means of having a thread work with the underlying HTTP server TCP/IP ports, is that correct?

I plan to try it out tomorrow - thanks again for sharing this. My use case is very simple, I could certainly get by with the HTTP Server handling requests synchronously, but it would be much more elegant to handle them async. Even on an ESP32. I wonder if requests could be made available for handling on the second code... perhaps httpd_queue_work does this - so much to learn :-)