Seeking code to find a free TCP/IP port

I know some modules search for a free port during testing, but I can't think of any specific one ATM. Any suggestions?


Tldr, Net::EmptyPort

Test::TCP does this, but would it be possible to just create a socket and let the OS assign it an ephemeral port, and use that in your application?

I should also mention that I have never used the above module, I had just seen it. I have been recommended to share another technique seen here:

Exactly, you can just omit port during listen, OS will pick random free port.

Leave a comment

About Ron Savage

user-pic I try to write all code in Perl, but find I end up writing in bash, CSS, HTML, JS, and SQL, and doing database design, just to get anything done...