[SOLVED] ESP32-S3 IDF 5.2.x - httpd setting socket options SO_REUSE_ADDR?

benjammin2068
Posts: 4
Joined: Tue Mar 26, 2024 1:32 am

[SOLVED] ESP32-S3 IDF 5.2.x - httpd setting socket options SO_REUSE_ADDR?

Postby benjammin2068 » Fri May 31, 2024 5:23 am

Hey all,

I have a working serial->UDP application and I recently added an HTTPD server for some user config... and that works too -- EXCEPT....

While the httpd server is running, I'm guessing it set up it's bind with options to NOT use SO_REUSEADDR.

So now, my UDP sending functions get the "Address already in use" errno 112 when trying to bind (SRCport:32768, DESTport:4000) (and it's TX only. no RX)

I'm guessing I have to somehow set the HTTP server to allow SO_REUSEADDR -- but how?

Is this an httpd_config.open_fn = <someFunction> operation or something else?

Thanks,

-Ben
Last edited by benjammin2068 on Fri May 31, 2024 5:04 pm, edited 1 time in total.

ESP_Sprite
Posts: 9582
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32-S3 IDF 5.2.x - httpd setting socket options SO_REUSE_ADDR?

Postby ESP_Sprite » Fri May 31, 2024 11:02 am

That doesn't make sense - the http server has nothing to do with your UDP ports and should not be affected by whatever port options it sets. You need to set SO_REUSEADDR on your UDP sockets.

benjammin2068
Posts: 4
Joined: Tue Mar 26, 2024 1:32 am

[SOLVED] Re: ESP32-S3 IDF 5.2.x - httpd setting socket options SO_REUSE_ADDR?

Postby benjammin2068 » Fri May 31, 2024 5:04 pm

And I looked in the source and see SO_REUSEADDR is now included -- so it was just how I was setting up my UDP packet sender.

The last post I searched and saw (from 2019) seemed to imply that SO_REUSEADDR was missing from the http server.

That's no longer the case.

This is in 5.2.x:

Code: Select all

    /* Enable SO_REUSEADDR to allow binding to the same
     * address and port when restarting the server */
    int enable = 1;
    if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable)) < 0) {
        /* This will fail if CONFIG_LWIP_SO_REUSE is not enabled. But
         * it does not affect the normal working of the HTTP Server */
        ESP_LOGW(TAG, LOG_FMT("error in setsockopt SO_REUSEADDR (%d)"), errno);
    }
So problem solved.

I'll leave this post here in case anyone else is wondering.

Who is online

Users browsing this forum: Baidu [Spider] and 177 guests