diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2011-12-05 00:37:34 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2011-12-05 00:37:34 (GMT) |
commit | 834545117011acd4272e96b2885d590037548aa4 (patch) | |
tree | 26b50ddbae805803367fe5ad0087d136978e6975 | |
parent | fa03f6c863c35204af5b618454f530dc5094ccff (diff) | |
download | cpython-834545117011acd4272e96b2885d590037548aa4.zip cpython-834545117011acd4272e96b2885d590037548aa4.tar.gz cpython-834545117011acd4272e96b2885d590037548aa4.tar.bz2 |
Use www.python.org instead of a hostname pointing to a parked (or squatted) domain.
Also, reformat a bit.
-rw-r--r-- | Doc/howto/sockets.rst | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/Doc/howto/sockets.rst b/Doc/howto/sockets.rst index 3d8ade9..603df59 100644 --- a/Doc/howto/sockets.rst +++ b/Doc/howto/sockets.rst @@ -60,11 +60,10 @@ Creating a Socket Roughly speaking, when you clicked on the link that brought you to this page, your browser did something like the following:: - #create an INET, STREAMing socket + # create an INET, STREAMing socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - #now connect to the web server on port 80 - # - the normal http port - s.connect(("www.mcmillan-inc.com", 80)) + # now connect to the web server on port 80 - the normal http port + s.connect(("www.python.org", 80)) When the ``connect`` completes, the socket ``s`` can be used to send in a request for the text of the page. The same socket will read the @@ -75,13 +74,11 @@ exchanges). What happens in the web server is a bit more complex. First, the web server creates a "server socket":: - #create an INET, STREAMing socket - serversocket = socket.socket( - socket.AF_INET, socket.SOCK_STREAM) - #bind the socket to a public host, - # and a well-known port + # create an INET, STREAMing socket + serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + # bind the socket to a public host, and a well-known port serversocket.bind((socket.gethostname(), 80)) - #become a server socket + # become a server socket serversocket.listen(5) A couple things to notice: we used ``socket.gethostname()`` so that the socket @@ -101,10 +98,10 @@ Now that we have a "server" socket, listening on port 80, we can enter the mainloop of the web server:: while True: - #accept connections from outside + # accept connections from outside (clientsocket, address) = serversocket.accept() - #now do something with the clientsocket - #in this case, we'll pretend this is a threaded server + # now do something with the clientsocket + # in this case, we'll pretend this is a threaded server ct = client_thread(clientsocket) ct.run() |