socket programming HOWTO - correction for bind to ''

http://docs.python.org/howto/sockets.html it says: A couple things to notice: we used socket.gethostname() so that the socket would be visible to the outside world. If we had used s.bind(('',80)) or s.bind(('localhost', 80)) or s.bind(('127.0.0.1', 80)) we would still have a “server” socket, but one that was only visible within the same machine. Actually I believe if you do s.bind(('',80)), that corresponds to INADDR_ANY for the host which means that socket is visible to the outside world. I.e. the socket will respond to any incoming connection to the host. Binding it to socket.gethostname() means it will respond to a specific incoming connection to that hostname. Thus if you have a multi-homed host (multiple hostnames for the machine), it will respond to only one specific hostname. so I would correct the example code from serversocket.bind((socket.gethostname(), 80)) to serversocket.bind(('', 80)) and the text to say A couple things to notice: we used the empty string ('') so that the socket would be visible to the outside world. If we had used s.bind(('localhost', 80)) or s.bind(('127.0.0.1', 80)) we would still have a “server” socket, but one that was only visible within the same machine.
participants (1)
-
David Lim