binding to localhost - slightly OT

A

Ajay

hi!

I am making the following call on my PDA which has WLAN connectivitythis 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.

thanks

cheers
 
A

Alex Martelli

Ajay said:
I am making the following call on my PDA which has WLAN connectivity
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.


Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,206
Messages
2,571,069
Members
47,678
Latest member
Aniruddha Das

Latest Threads

Top