in reply to Re: Re: IO::Socket
in thread IO::Socket

Your server, by definition listens on the local machine. By giving it a hostname or IP address to listen on, you are telling it that it needs to use its "ears" on that particular hostname/IP, and only listen for connections with that as their destination. Thus, if you use "localhost", only clients on the local machine will be able to connect to the server process, and even then only if they are making their connection to "localhost" or 127.0.0.1.

All machines with an IP stack usually have at least two IP addresses associated with it: The normal IP address that you use to make connections to the machine from other hosts, and a loopback address 127.0.0.1, which by definition refers to the "local host". The LocalAddr option does not mean "listen for connections coming from clients on the given host", it means "listen for connections from clients connecting *to* the given host, which is this machine". It will fail if the hostname or IP address you give it is not a valid IP address for the host the server is running on.

So generally, omit the LocalAddr option unless you have an explicit need to only listen on a single interface, ignoring connection attempts being made to other interfaces on the same host. Omitting it is the same as using a LocalAddr of 0.0.0.0, or a wildcard IP, meaning it'll accept connections on all local interfaces, which is usually what you want.

Does this make sense? I'd also check out the documentation for bind, as this is how LocalAddr is implemented. That might give you some more detail.

Replies are listed 'Best First'.
Re: Re: Re: Re: IO::Socket
by dsb (Chaplain) on Feb 07, 2001 at 23:57 UTC
    Yeah, that makes alot of sense. I guess I didn't word my question properly though. What I am asking is how do I specify and IP to connect *to* in the client socket script? That is where I am having trouble. The server script runs fine. I did take the LocalAddr attribute out and it still makes the connection and listens. Everything is fine there. The client is the problem. The connection consistently fails unless I put it on the same machine as the server and specify 'localhost' in the PeerAddr attribute. - kel -
      The client needs to make use of the PeerAddr field in your IO::Socket::INET constructor, or via the object's connect call. Any valid IP/hostname for the server should work fine. Note that IO::Socket reports its errors in $@, not $!, so printing out the value of this variable may be helpful in identifying the problem. There's no reason this shouldn't work, unless the problem is external (firewall or network), or if you're using an invalid hostname/IP.
        Okay. This is the code I am using to create the client socket. I have tried the PeerAddr with both a 4 byte IP number, and the domain name and nothing has worked. It dies with the IP, and it hangs with the domain.
        $sock = new IO::Socket::INET( PeerAddr => 'dev01.nerds.com', PeerPort => 1200, Proto => 'tcp', Type => SOCK_STREAM );
        What am I doing wrong? I am at a total loss. - kel -