lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

* On 2010-04-12 Andreas Falkenhahn <> wrote  :

> Hi,
> 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 I can't imagine a case
> where I'd need to set this to a different address than 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; this will allow incoming connections to the
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 (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, and, you could bind the server socket to, so
incoming connections on are not accepted.