I am currently working on a TCP server that will run on ESp32 and ESp32-S3.
This should only run for a few seconds and then process another task. This should repeat every minute.
I have managed this so far, but unfortunately I get the error “bind error: Address already in use” every time I switch on the server. I then added the socket option “SO_REUSEADDR”, but unfortunately the error still occurs.
Question, is it possible to enable the setsockopt() - option “SO_REUSEADDR” with the framework=arduino?
Unfortunately the framework was given to me by my internship company.
The above code are just 2 functions, to make sure we’re seeing the same things and test the same things, this needs ot be a complete + minimal code, but it’s missing setup() and loop() and the includes.
A general observation is that the code is not very Arduino-y. It uses the socket API provided by lwIP and not WiFiServer, WiFiClient objects and library, with which one would typically program a server on an Arduino. See e.g. https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/examples/SimpleWiFiServer/SimpleWiFiServer.ino. The code reads more like it was ripped from a Linux reference program with a few Arduino printlns and FreeRTOS calls sprinkled in between. I’m sure the libraries would handle a few things for you that you would not need to do manually.
The bool Anmeldeserver() returns non boolean values casted to bool very often, such as return(EXIT_FAILURE);. Since EXIT_FAILURE evlauates to 8 normally, and 8 is a truthy value since it’s not 0, the function would return true when it’s encountered a fatal error. This is very counter-intuitive, as bool return values typically mean true = it worked, false = fail.