[Python-checkins] cpython (2.7): bind('') does not do the same as bind('localhost')

georg.brandl python-checkins at python.org
Sun Apr 14 10:58:57 CEST 2013


http://hg.python.org/cpython/rev/66ca6d85eb95
changeset:   83336:66ca6d85eb95
branch:      2.7
parent:      83333:dd5e7aef4d5b
user:        Georg Brandl <georg at python.org>
date:        Sun Apr 14 10:59:04 2013 +0200
summary:
  bind('') does not do the same as bind('localhost')

files:
  Doc/howto/sockets.rst |  8 +++++---
  1 files changed, 5 insertions(+), 3 deletions(-)


diff --git a/Doc/howto/sockets.rst b/Doc/howto/sockets.rst
--- a/Doc/howto/sockets.rst
+++ b/Doc/howto/sockets.rst
@@ -88,9 +88,11 @@
    serversocket.listen(5)
 
 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.
+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.  ``s.bind(('', 80))``
+specifies that the socket is reachable by any address the machine happens to
+have.
 
 A second thing to note: low number ports are usually reserved for "well known"
 services (HTTP, SNMP etc). If you're playing around, use a nice high number (4

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list