Secure WSS; how do I create more than one server?(SOLVED!)

BenBurger
Posts: 10
Joined: Sat Jan 07, 2023 12:05 pm

Secure WSS; how do I create more than one server?(SOLVED!)

Postby BenBurger » Wed Sep 27, 2023 7:33 pm

Hi all

Can anyone help with WSS socket server
I want to create 2 servers sending different data on 2 different ports 9000 and 443 for now
HOWEVER the first one works but never the second one

I (4957) : Starting server
I (4957) esp_https_server: Starting server
I (4957) esp_https_server: Server listening on port 443
I (4957) : Registering URI handlers
I (4957) : Starting server
I (4967) esp_https_server: Starting server
E (4967) httpd: httpd_server_init: error in creating ctrl socket (112)
I (4977) : Error starting server!


I have duplicated almost all the functions yet it fails
.............................
httpd_ssl_config_t conf = HTTPD_SSL_CONFIG_DEFAULT();
conf.httpd.max_open_sockets = max_clients;
conf.httpd.global_user_ctx = keep_alive;
conf.port_secure = 9000;
conf.httpd.open_fn = wss_open_fd1;
conf.httpd.close_fn = wss_close_fd1;

....................
httpd_ssl_config_t conf = HTTPD_SSL_CONFIG_DEFAULT();
conf.httpd.max_open_sockets = max_clients;
conf.httpd.global_user_ctx = keep_alive;
conf.port_secure = 443;
conf.httpd.open_fn = wss_open_fd;
conf.httpd.close_fn = wss_close_fd;

#ifdef CONFIG_EXAMPLE_CONNECT_WIFI
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &connect_handler, &server));
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED, &disconnect_handler, &server));
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &connect_handler1, &server1));
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED, &disconnect_handler1, &server1));

#endif // CONFIG_EXAMPLE_CONNECT_WIFI

/* This helper function configures Wi-Fi or Ethernet, as selected in menuconfig.
* Read "Establishing Wi-Fi or Ethernet Connection" section in
* examples/protocols/README.md for more information about this function.
*/
ESP_ERROR_CHECK(example_connect());

/* This function demonstrates periodic sending Websocket messages
* to all connected clients to this server
*/
wss_server_send_messages(&server);
wss_server_send_messages1(&server1);

Any help will be appreciated what am I missing here
tx
Ben
Last edited by BenBurger on Thu Sep 28, 2023 4:11 pm, edited 1 time in total.

MicroController
Posts: 1701
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Secure WSS; how do I create more than one server?

Postby MicroController » Wed Sep 27, 2023 10:39 pm

E (4967) httpd: httpd_server_init: error in creating ctrl socket (112)
Try and give each server instance its own control port:

Code: Select all

httpd_ssl_config_t conf = HTTPD_SSL_CONFIG_DEFAULT();
...
conf.httpd.ctrl_port  = conf.httpd.ctrl_port + (my_server_instance_number++);
...

BenBurger
Posts: 10
Joined: Sat Jan 07, 2023 12:05 pm

Re: Secure WSS; how do I create more than one server?

Postby BenBurger » Thu Sep 28, 2023 3:44 pm

Thanks tried it, something changed, now the error also changed

I (4967) esp_https_server: Starting server
E (4967) httpd: httpd_server_init: error in creating msg socket (23)
I (4977) : Error starting server!

BenBurger
Posts: 10
Joined: Sat Jan 07, 2023 12:05 pm

Re: Secure WSS; how do I create more than one server? (SOLVED!!)

Postby BenBurger » Thu Sep 28, 2023 4:07 pm

Ah found the issues !!!!

LWIP Max number of open sockets : was 5 set it to 10 and now working
seems each socket needs (sockets + 3)*2 ===>
comment in httpd_main.c
.......................................
/* Sanity check about whether LWIP is configured for providing the
* maximum number of open sockets sufficient for the server. Though,
* this check doesn't guarantee that many sockets will actually be
* available at runtime as other processes may use up some sockets.
* Note that server also uses 3 sockets for its internal use :
* 1) listening for new TCP connections
* 2) for sending control messages over UDP
* 3) for receiving control messages over UDP
* So the total number of required sockets is max_open_sockets + 3
*/

Who is online

Users browsing this forum: Majestic-12 [Bot] and 227 guests