lua-users home
lua-l archive

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



* On 2010-04-12 Andreas Falkenhahn <andreas@airsoftsoftwair.de> 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 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.

-- 
:wq
^X^Cy^K^X^C^C^C^C