in reply to Re: 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

That's a good trick to know, but it won't work for me, since the server I'm starting is written in C++. My Perl code is an external controller for the server and will also act as a client. (UPDATE: FYI it's a test script)

--DrWhy

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

  • Comment on Re^2: What's the best way to find an unused TCP port on the local system

Replies are listed 'Best First'.
Re^3: What's the best way to find an unused TCP port on the local system
by ikegami (Patriarch) on Oct 20, 2006 at 20:11 UTC
    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.
      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