Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a204636

Browse files
committed
bind('') does not do the same as bind('localhost')
1 parent 5f4b4ac commit a204636

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

Doc/howto/sockets.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,11 @@ creates a "server socket"::
8484
serversocket.listen(5)
8585

8686
A couple things to notice: we used ``socket.gethostname()`` so that the socket
87-
would be visible to the outside world. If we had used ``s.bind(('', 80))`` or
88-
``s.bind(('localhost', 80))`` or ``s.bind(('127.0.0.1', 80))`` we would still
89-
have a "server" socket, but one that was only visible within the same machine.
87+
would be visible to the outside world. If we had used ``s.bind(('localhost',
88+
80))`` or ``s.bind(('127.0.0.1', 80))`` we would still have a "server" socket,
89+
but one that was only visible within the same machine. ``s.bind(('', 80))``
90+
specifies that the socket is reachable by any address the machine happens to
91+
have.
9092

9193
A second thing to note: low number ports are usually reserved for "well known"
9294
services (HTTP, SNMP etc). If you're playing around, use a nice high number (4

0 commit comments

Comments
 (0)