Ordinary_User has asked for the wisdom of the Perl Monks concerning the following question:

Greetings, fellow Monks!

I'm writing a script that will use IO::Socket::INET to connect to a server script, also using IO::Socket::INET.
The two scripts talk to each other very nicely, so far so good. The problem I have is that every connection the client makes, comes from a random port number. The server port number is allways the same but the port number that the client uses is allways random.

What I'm wondering is, if there is any way to specify what local port the client should be using when making a connection to the server?

I need the two clients to communicate over a single port number since I have only one port number open in my firewall. (Changing the FW-settings is not an option, though)

Thanx for taking the time to read my question!

"May the forces of high bandwidth be with you."
  • Comment on Socket: Specifying client port to connect from

Replies are listed 'Best First'.
Re: Socket: Specifying client port to connect from
by sauoq (Abbot) on Oct 21, 2003 at 09:23 UTC
    What I'm wondering is, if there is any way to specify what local port the client should be using when making a connection to the server?

    Yes. Just include the LocalPort parameter when you call IO::Socket::INET->new().

    It works as advertised. It is usually used when listening, but it does the right thing when initiating a connection as well.

    -sauoq
    "My two cents aren't worth a dime.";
    
      It works just fine!

      Many thanks for your help!

      "May the forces of high bandwidth be with you."