First, thank you for this amazing library! Second, my apologies if this was somewhere in the documentation, I was unable to find a clean way to do what I want to do. I am very new to the project and so it is very possible I missed something.
My use case: I am configuring an application that will start a Flask-SocketIO server per user session; these sessions (and thus servers) are all running on a single machine hosting the main application, and therefore I need to run each SocketIO server on a separate port. I want to be able to not just programmatically provide a random port for the Flask-SocketIO server, but also retrieve that port number and return it to the user through their session's interface.
I am very easily able to tell eventlet
to use a random port by just always running with:
socketio.run(app, port=0)
But I need to be able to grab whatever port was allocated (users won't be able to see stdout, so log_output=True
is useful for debugging on my end, but not deployment). My workaround for now was to grab the code implemented here (and for now set addresses = eventlet.green.socket.getaddrinfo('localhost', '0')
) and retrieve the address with:
f'localhost:{eventlet_socket.getsockname()[1]}'
Is there a more elegant way to achieve this? I would much prefer not to pull code out from the library, but it does work well enough for my current purposes. I also do not want to bind a random port, release it, and then try to use it, as I do not want to encounter the off chance that the port is used in the small window after it is released.
Thanks again for all of the amazing work, and thanks for any guidance!