binding to localhost - slightly OT
aleaxit at yahoo.com
Wed Sep 22 11:51:31 CEST 2004
Ajay <abra9823 at mail.usyd.edu.au> wrote:
> I am making the following call on my PDA which has WLAN connectivity
> >>>import socket
> this prints 127.0.0.1
> the PDA has an assigned IP address.
> so if i go
> UDPserversocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
> UDPserversocket.bind((socket.gethostname(), LOCAL_SERVER_PORT))
> this binds to the localhost instead of the assigned IP address. how can i
> get it to bind to the assigned IP? i dont want to explicitly enter the IP
> address into the bind call, since the IP may change.
If you .bind to a specific address, you are only going to be reachable
from that address -- is that what you're trying to do? If so, then any
of the addresses for your host should be just as good (or just as bad).
I suspect that what you're TRYING to do is bind(socket.INADDR_ANY, ...
so that OTHER machines can send you datagrams... I believe a '' would
also work as the first argument to bind, instead of INADDR_ANY.
More information about the Python-list