[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Getting multiple IP addresses using luasocket
- From: William Ahern <william@...>
- Date: Wed, 15 Jan 2014 16:11:54 -0800
On Wed, Jan 15, 2014 at 09:31:39AM -0800, Paul K wrote:
> Hi William,
>
> > The canonical way to do this is to create and bind a socket to a known
> > public address, such as 8.8.8.8 (Google's public DNS service) and then call
> > getsockname to get the local IP. You don't even need to connect the socket.
> > The socket bind will force the kernel to resolve the proper local address
> > according to its routing table.
>
> Thank you for the suggestion. I did get it working, but not without
> connecting to the socket:
>
> socket.connect('8.8.8.8', 53):getsockname()
>
> I tried something similar using socket.bind, but it only binds to
> local addresses (to create a listening socket). Am I missing something
> in the luasocket API?
>
Oops. Actually, I was wrong--you do need to connect. Sorry.
But if you create a UDP socket instead of TCP, there's no handshake involved
so it's instantaneous.