Micropython, clearing old server socket addresses on startup

I am using the Arduino Lab for Micropython to program a NanoESP32. Everythin worksfine and I can connect to my WLAN and set up a server on the NanoESP32. If the server is shut down correctly the server_socket closes (with server_socket.close()), problems arise when the device is reset using the onboard button or power is removed from the device. Then when the script is run in the Arduino Lab for Micropython it gives the error OSError: [Errno 112] EADDRINUSE and the only way I can set up a new server_socket is by changing the port.

I thought that if I cleared all server_socket instances in the script before setting up a new one might solve the problem. So I tried putting the following at the start of my script:

# List to hold all server sockets
server_sockets = []

# Close all server sockets

for server_socket in server_sockets:
    server_socket.close()
server_sockets.clear()

This didn't work, I still get the "address in use" error. How can I clear the server_sockets, or is there a better way to do this?

Anything in these search results? esp32 EADDRINUSE - Google Search

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.