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
d790a7b5
Kaydet (Commit)
d790a7b5
authored
Ock 17, 2006
tarafından
Fredrik Lundh
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
fixed example:
adding missing import, handle_close, test code, etc.
üst
61532012
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
11 deletions
+19
-11
libasyncore.tex
Doc/lib/libasyncore.tex
+19
-11
No files found.
Doc/lib/libasyncore.tex
Dosyayı görüntüle @
d790a7b5
...
@@ -222,29 +222,37 @@ Most of these are nearly identical to their socket partners.
...
@@ -222,29 +222,37 @@ Most of these are nearly identical to their socket partners.
\subsection
{
asyncore Example basic HTTP client
\label
{
asyncore-example
}}
\subsection
{
asyncore Example basic HTTP client
\label
{
asyncore-example
}}
As a basic example, below is a very basic HTTP client that uses the
Here is a very basic HTTP client that uses the
\class
{
dispatcher
}
\class
{
dispatcher
}
class to implement its socket handling:
class to implement its socket handling:
\begin{verbatim}
\begin{verbatim}
import asyncore, socket
class http
_
client(asyncore.dispatcher):
class http
_
client(asyncore.dispatcher):
def
__
init
__
(self, host,path):
def
__
init
__
(self, host, path):
asyncore.dispatcher.
__
init
__
(self)
asyncore.dispatcher.
__
init
__
(self)
self.path = path
self.create
_
socket(socket.AF
_
INET, socket.SOCK
_
STREAM)
self.create
_
socket(socket.AF
_
INET, socket.SOCK
_
STREAM)
self.connect( (host, 80) )
self.connect( (host, 80) )
self.buffer = 'GET
%s HTTP/1.0\r\n\r\n' %
self.
path
self.buffer = 'GET
%s HTTP/1.0\r\n\r\n' % path
def handle
_
connect(self):
def handle
_
connect(self):
pass
pass
def handle
_
close(self):
self.close()
def handle
_
read(self):
def handle
_
read(self):
data = self.recv(8192)
print self.recv(8192)
print data
def writable(self):
def writable(self):
return (len(self.buffer) > 0)
return (len(self.buffer) > 0)
def handle
_
write(self):
def handle
_
write(self):
sent = self.send(self.buffer)
sent = self.send(self.buffer)
self.buffer = self.buffer[sent:]
self.buffer = self.buffer[sent:]
c = http
_
client('www.python.org', '/')
asyncore.loop()
\end{verbatim}
\end{verbatim}
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