in reply to Re: Re: local socket
in thread local socket

I don't remember where I learned about restricting sockets to specific addresses, and I can't find any really descriptive information on it. Very frustrating... :(

Here is a relevant snippet from perlipc:

And here's a corresponding server to go along with it. We'll leave the address as INADDR_ANY so that the kernel can choose the appropriate interface on multihomed hosts. If you want sit on a particular interface (like the external side of a gateway or firewall machine), you should fill this in with your real address instead.
And here's something from Socket:
INADDR_ANY Note: does not return a number, but a packed string. Returns the 4-byte wildcard ip address which specifies any of the hosts ip addresses. (A particular machine can have more than one ip address, each address corresponding to a particular network interface. This wildcard address allows you to bind to all of them simultaneously.) Normally equivalent to inet_aton('0.0.0.0').
Let's say you have a machine that has two IP addresses: mymachine.example.com and foo.bar.baz.com. A server program which binds to the address mymachine.example.com will only accept connections made to mymachine.example.com. A program which binds to foo.bar.baz.com will only accept connections to foo.bar.baz.com, and a program that binds to localhost will only accept connections to localhost (which must, of course, also be from localhost).

On the other hand, a server program which binds to INADDR_ANY will accept connections made to any address that happens to resolve to the machine in question, including mymachine.example.com, foo.bar.baz.com, and localhost. That's usually what you want.

Replies are listed 'Best First'.
Ren: local socket
by John M. Dlugosz (Monsignor) on Jun 04, 2001 at 23:03 UTC
    OK, thanks. It's a mostly-ignored argument to bind(). It never occured to me to use it to select for localhost.

    Now I wonder if more than one listener can exist at the same time on the same port, with mutually exclusive addresses? So get one listener optomized for local connections, and one that works for all clients.

    —John

      Yes. I believe that you can even have one listener bound to a specific address and another bound to INADDR_ANY and connections will come only to the listener that is "most specifically" appropriate. However, this last case is the type of stuff that I never find documented.

              - tye (but my friends call me "Tye")