Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
83454511
Kaydet (Commit)
83454511
authored
Ara 05, 2011
tarafından
Antoine Pitrou
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Use www.python.org instead of a hostname pointing to a parked (or squatted) domain.
Also, reformat a bit.
üst
fa03f6c8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
13 deletions
+10
-13
sockets.rst
Doc/howto/sockets.rst
+10
-13
No files found.
Doc/howto/sockets.rst
Dosyayı görüntüle @
83454511
...
@@ -60,11 +60,10 @@ Creating a Socket
...
@@ -60,11 +60,10 @@ Creating a Socket
Roughly speaking, when you clicked on the link that brought you to this page,
Roughly speaking, when you clicked on the link that brought you to this page,
your browser did something like the following::
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)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#now connect to the web server on port 80
# now connect to the web server on port 80 - the normal http port
# - the normal http port
s.connect(("www.python.org", 80))
s.connect(("www.mcmillan-inc.com", 80))
When the ``connect`` completes, the socket ``s`` can be used to send
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
in a request for the text of the page. The same socket will read the
...
@@ -75,13 +74,11 @@ exchanges).
...
@@ -75,13 +74,11 @@ exchanges).
What happens in the web server is a bit more complex. First, the web server
What happens in the web server is a bit more complex. First, the web server
creates a "server socket"::
creates a "server socket"::
#create an INET, STREAMing socket
# create an INET, STREAMing socket
serversocket = socket.socket(
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socket.AF_INET, socket.SOCK_STREAM)
# bind the socket to a public host, and a well-known port
#bind the socket to a public host,
# and a well-known port
serversocket.bind((socket.gethostname(), 80))
serversocket.bind((socket.gethostname(), 80))
#become a server socket
#
become a server socket
serversocket.listen(5)
serversocket.listen(5)
A couple things to notice: we used ``socket.gethostname()`` so that the socket
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
...
@@ -101,10 +98,10 @@ Now that we have a "server" socket, listening on port 80, we can enter the
mainloop of the web server::
mainloop of the web server::
while True:
while True:
#accept connections from outside
#
accept connections from outside
(clientsocket, address) = serversocket.accept()
(clientsocket, address) = serversocket.accept()
#now do something with the clientsocket
#
now do something with the clientsocket
#in this case, we'll pretend this is a threaded server
#
in this case, we'll pretend this is a threaded server
ct = client_thread(clientsocket)
ct = client_thread(clientsocket)
ct.run()
ct.run()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment