[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: LuaSocket: Rationale behind address arg in socket.bind
- From: Ico <lua@...>
- Date: Mon, 12 Apr 2010 16:27:30 +0200
* On 2010-04-12 Andreas Falkenhahn <email@example.com> wrote :
> could someone briefly explain to me the rationale behind the "address" argument in
> LuaSocket's socket.bind() function? Specifically, I'm wondering why this argument
> is needed at all... shouldn't this always be set to 127.0.0.1? I can't imagine a case
> where I'd need to set this to a different address than 127.0.0.1 but then again, I'm
> just starting out with LuaSocket (& sockets in general)....
When writing network services, you generally do not want to bind to the
address 127.0.0.1; this will allow incoming connections to the 127.0.0.1
address only, and since this address is only reachable from the host
itself, it can only be used for loopback purposes, e.g. the client is
running on the same machine as the server.
To listen on all available interfaces, the address 0.0.0.0 (INADDR_ANY)
is used to indicate the socket is allowed to accept connections for any
of the addresses of any of the network interfaces.
A third option is to bind to a specific address of one of the
interfaces, this is usually used for multi-homed machines with more then
one network interface. For example, if your machine has two addresses,
10.0.0.1 and 10.0.0.2, you could bind the server socket to 10.0.0.1, so
incoming connections on 10.0.0.2 are not accepted.