in reply to Re^2: What's the best way to find an unused TCP port on the local system
in thread What's the best way to find an unused TCP port on the local system

This is not a Perl "trick". It's a feature of the system's socket library. You can use port 0 in C++ as well.
  • Comment on Re^3: What's the best way to find an unused TCP port on the local system

Replies are listed 'Best First'.
Re^4: What's the best way to find an unused TCP port on the local system
by DrWhy (Chaplain) on Oct 20, 2006 at 21:43 UTC
    It must be a feature only of Unix(-like) systems, then. I'm working in a Windows XP environment and just tried it out with our c++ server and instead of picking a random port it actually connected to port number 0.

    Updated: No, it works as described in the previous post. Our server is just reporting (incorrectly) that it is connected to port 0.

    --DrWhy

    "If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."

      No, it works on Windows XP as well. bind() is what typically assigns the port number. But this has become quite off topic. There are lots of choices for networking APIs to use in Windows XP from C++, so you should probably consult the documentation for whichever one you are using.

      - tye