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
b1af86a1
Kaydet (Commit)
b1af86a1
authored
Tem 03, 2002
tarafından
Steve Holden
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Revise asyncore documentation and document asynchat for the first time.
üst
df872a20
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
347 additions
and
55 deletions
+347
-55
Makefile.deps
Doc/Makefile.deps
+1
-0
lib.tex
Doc/lib/lib.tex
+1
-0
libasynchat.tex
Doc/lib/libasynchat.tex
+254
-0
libasyncore.tex
Doc/lib/libasyncore.tex
+91
-55
No files found.
Doc/Makefile.deps
Dosyayı görüntüle @
b1af86a1
...
@@ -315,6 +315,7 @@ LIBFILES= $(MANSTYLES) $(INDEXSTYLES) $(COMMONTEX) \
...
@@ -315,6 +315,7 @@ LIBFILES= $(MANSTYLES) $(INDEXSTYLES) $(COMMONTEX) \
lib/libstatvfs.tex
\
lib/libstatvfs.tex
\
lib/libtty.tex
\
lib/libtty.tex
\
lib/libasyncore.tex
\
lib/libasyncore.tex
\
lib/libasynchat.tex
\
lib/libatexit.tex
\
lib/libatexit.tex
\
lib/libmmap.tex
\
lib/libmmap.tex
\
lib/tkinter.tex
\
lib/tkinter.tex
\
...
...
Doc/lib/lib.tex
Dosyayı görüntüle @
b1af86a1
...
@@ -217,6 +217,7 @@ and how to embed it in other applications.
...
@@ -217,6 +217,7 @@ and how to embed it in other applications.
\input
{
libxmlrpclib
}
\input
{
libxmlrpclib
}
\input
{
libsimplexmlrpc
}
\input
{
libsimplexmlrpc
}
\input
{
libasyncore
}
\input
{
libasyncore
}
\input
{
libasynchat
}
\input
{
netdata
}
% Internet Data Handling
\input
{
netdata
}
% Internet Data Handling
\input
{
libformatter
}
\input
{
libformatter
}
...
...
Doc/lib/libasynchat.tex
0 → 100644
Dosyayı görüntüle @
b1af86a1
\section
{
\module
{
asynchat
}
---
Asynchronous socket command/response handler
}
\declaremodule
{
standard
}{
asynchat
}
\modulesynopsis
{
Support for asynchronous command/response protocols.
}
\moduleauthor
{
Sam Rushing
}{
rushing@nightmare.com
}
\sectionauthor
{
Steve Holden
}{
sholden@holdenweb.com
}
This module builds on the
\refmodule
{
asyncore
}
infrastructure,
simplifying asynchronous clients and servers and making it easier to
handle protocols whose elements are terminated by arbitrary strings, or
are of variable length.
\refmodule
{
asynchat
}
defines the abstract class
\class
{
async
_
chat
}
that you subclass, providing implementations of the
\method
{
collect
_
incoming
_
data()
}
and
\method
{
found
_
terminator()
}
methods. It uses the same asynchronous loop as
\refmodule
{
asyncore
}
, and
the two types of channel,
\class
{
asyncore.despatcher
}
and
\class
{
asynchat.async
_
chat
}
, can freely be mixed in the channel map.
Typically an
\class
{
asyncore.despatcher
}
server channel generates new
\class
{
asynchat.async
_
chat
}
channel objects as it receives incoming
connection requests.
\begin{classdesc}
{
async
_
chat
}{}
This class is an abstract subclass of
\class
{
asyncore.despatcher
}
. To make
practical use of the code you must subclass
\class
{
async
_
chat
}
, providing
meaningful
\method
{
collect
_
incoming
_
data()
}
and
\method
{
found
_
terminator()
}
methods. The
\class
{
asyncore.despatcher
}
methods can be
used, although not all make sense in a message/response context.
Like
\class
{
asyncore.despatcher
}
,
\class
{
async
_
chat
}
defines a set of events
that are generated by an analysis of socket conditions after a
\cfunction
{
select()
}
call. Once the polling loop has been started the
\class
{
async
_
chat
}
object's methods are called by the event-processing
framework with no action on the part of the programmer.
Unlike
\class
{
asyncore.despatcher
}
,
\class
{
async
_
chat
}
allows you to define
a first-in-first-out queue (fifo) of
\emph
{
producers
}
. A producer need have
only one method,
\method
{
more()
}
, which should return data to be transmitted
on the channel. The producer indicates exhaustion (
\emph
{
i.e.
}
that it contains
no more data) by having its
\method
{
more()
}
method return the empty string. At
this point the
\class
{
async
_
chat
}
object removes the producer from the fifo
and starts using the next producer, if any. When the producer fifo is empty
the
\method
{
handle
_
write()
}
method does nothing. You use the channel object's
\method
{
set
_
terminator()
}
method to describe how to recognize the end
of, or an important breakpoint in, an incoming transmission from the
remote endpoint.
To build a functioning
\class
{
async
_
chat
}
subclass your
input methods
\method
{
collect
_
incoming
_
data()
}
and
\method
{
found
_
terminator()
}
must handle the data that the channel receives
asynchronously. The methods are described below.
\end{classdesc}
\begin{methoddesc}
{
close
_
when
_
done
}{}
Pushes a
\code
{
None
}
on to the producer fifo. When this producer is
popped off the fifo it causes the channel to be closed.
\end{methoddesc}
\begin{methoddesc}
{
collect
_
incoming
_
data
}{
data
}
Called with
\var
{
data
}
holding an arbitrary amount of received data.
The default method, which must be overridden, raises a
\exception
{
NotImplementedError
}
exception.
\end{methoddesc}
\begin{methoddesc}
{
discard
_
buffers
}{}
In emergencies this method will discard any data held in the input and/or
output buffers and the producer fifo.
\end{methoddesc}
\begin{methoddesc}
{
found
_
terminator
}{}
Called when the incoming data stream matches the termination condition
set by
\method
{
set
_
terminator
}
. The default method, which must be overridden,
raises a
\exception
{
NotImplementedError
}
exception. The buffered input data should
be available via an instance attribute.
\end{methoddesc}
\begin{methoddesc}
{
get
_
terminator
}{}
Returns the current terminator for the channel.
\end{methoddesc}
\begin{methoddesc}
{
handle
_
close
}{}
Called when the channel is closed. The default method silently closes
the channel's socket.
\end{methoddesc}
\begin{methoddesc}
{
handle
_
read
}{}
Called when a read event fires on the channel's socket in the
asynchronous loop. The default method checks for the termination
condition established by
\method
{
set
_
terminator()
}
, which can be either
the appearance of a particular string in the input stream or the receipt
of a particular number of characters. When the terminator is found,
\method
{
handle
_
read
}
calls the
\method
{
found
_
terminator()
}
method after
calling
\method
{
collect
_
incoming
_
data()
}
with any data preceding the
terminating condition.
\end{methoddesc}
\begin{methoddesc}
{
handle
_
write
}{}
Called when the application may write data to the channel.
The default method calls the
\method
{
initiate
_
send()
}
method, which in turn
will call
\method
{
refill
_
buffer()
}
to collect data from the producer
fifo associated with the channel.
\end{methoddesc}
\begin{methoddesc}
{
push
}{
data
}
Creates a
\class
{
simple
_
producer
}
object (
\emph
{
see below
}
) containing the data and
pushes it on to the channel's
\code
{
producer
_
fifo
}
to ensure its
transmission. This is all you need to do to have the channel write
the data out to the network, although it is possible to use your
own producers in more complex schemes to implement encryption and
chunking, for example.
\end{methoddesc}
\begin{methoddesc}
{
push
_
with
_
producer
}{
producer
}
Takes a producer object and adds it to the producer fifo associated with
the channel. When all currently-pushed producers have been exhausted
the channel will consume this producer's data by calling its
\method
{
more()
}
method and send the data to the remote endpoint.
\end{methoddesc}
\begin{methoddesc}
{
readable
}{}
Should return
\code
{
True
}
for the channel to be included in the set of
channels tested by the
\cfunction
{
select()
}
loop for readability.
\end{methoddesc}
\begin{methoddesc}
{
refill
_
buffer
}{}
Refills the output buffer by calling the
\method
{
more()
}
method of the
producer at the head of the fifo. If it is exhausted then the
producer is popped off the fifo and the next producer is activated.
If the current producer is, or becomes,
\code
{
None
}
then the channel
is closed.
\end{methoddesc}
\begin{methoddesc}
{
set
_
terminator
}{
term
}
Sets the terminating condition to be recognised on the channel.
\code
{
term
}
may be any of three types of value, corresponding to three different ways
to handle incoming protocol data.
\begin{tableii}
{
l|l
}{}{
term
}{
Description
}
\lineii
{
\emph
{
string
}}{
Will call
\method
{
found
_
terminator()
}
when the
string is found in the input stream
}
\lineii
{
\emph
{
integer
}}{
Will call
\method
{
found
_
terminator()
}
when the
indicated number of characters have been received
}
\lineii
{
\code
{
None
}}{
The channel continues to collect data forever
}
\end{tableii}
Note that any data following the terminator will be available for reading by
the channel after
\method
{
found
_
terminator()
}
is called.
\end{methoddesc}
\begin{methoddesc}
{
writable
}{}
Should return
\code
{
True
}
as long as items remain on the producer fifo,
or the channel is connected and the channel's output buffer is non-empty.
\end{methoddesc}
\subsection
{
asynchat - Auxiliary Classes and Functions
}
\begin{classdesc}
{
simple
_
producer
}{
data
\optional
{
, buffer
_
size=512
}}
A
\class
{
simple
_
producer
}
takes a chunk of data and an optional buffer size.
Repeated calls to its
\method
{
more()
}
method yield successive chunks of the
data no larger than
\var
{
buffer
_
size
}
.
\end{classdesc}
\begin{methoddesc}
{
more
}{}
Produces the next chunk of information from the producer, or returns the empty string.
\end{methoddesc}
\begin{classdesc}
{
fifo
}{
\optional
{
list=None
}}
Each channel maintains a
\class
{
fifo
}
holding data which has been pushed by the
application but not yet popped for writing to the channel.
A
\class
{
fifo
}
is a list used to hold data and/or producers until they are required.
If the
\var
{
list
}
argument is provided then it should contain producers or
data items to be written to the channel.
\end{classdesc}
\begin{methoddesc}
{
is
_
empty
}{}
Returns
\code
{
True
}
iff the fifo is empty.
\end{methoddesc}
\begin{methoddesc}
{
first
}{}
Returns the least-recently
\method
{
push()
}
ed item from the fifo.
\end{methoddesc}
\begin{methoddesc}
{
push
}{
data
}
Adds the given data (which may be a string or a producer object) to the
producer fifo.
\end{methoddesc}
\begin{methoddesc}
{
pop
}{}
If the fifo is not empty, returns
\code
{
True, first()
}
, deleting the popped
item. Returns
\code
{
False, None
}
for an empty fifo.
\end{methoddesc}
The
\module
{
asynchat
}
module also defines one utility function, which may be
of use in network and textual analysis operations.
\begin{funcdesc}
{
find
_
prefix
_
at
_
end
}{
haystack, needle
}
Returns
\code
{
True
}
if string
\var
{
haystack
}
ends with any non-empty
prefix of string
\var
{
needle
}
.
\end{funcdesc}
\subsection
{
asynchat Example
\label
{
asynchat-example
}}
The following partial example shows how HTTP requests can be read with
\class
{
async
_
chat
}
. A web server might create an
\class
{
http
_
request
_
handler
}
object for
each incoming client connection. Notice that initially the
channel terminator is set to match the blank line at the end of the HTTP
headers, and a flag indicates that the headers are being read.
Once the headers have been read, if the request is of type POST
(indicating that further data are present in the input stream) then the
\code
{
Content-Length:
}
header is used to set a numeric terminator to
read the right amount of data from the channel.
The
\method
{
handle
_
request()
}
method is called once all relevant input
has been marshalled, after setting the channel terminator to
\code
{
None
}
to ensure that any extraneous data sent by the web client are ignored.
\begin{verbatim}
class http
_
request
_
handler(asynchat.async
_
chat):
def
__
init
__
(self, conn, addr, sessions, log):
asynchat.async
_
chat.
__
init
__
(self, conn=conn)
self.addr = addr
self.sessions = sessions
self.ibuffer = []
self.obuffer = ""
self.set
_
terminator("
\r\n\r\n
")
self.reading
_
headers = True
self.handling = False
self.cgi
_
data = None
self.log = log
def collect
_
incoming
_
data(self, data):
"""Buffer the data"""
self.ibuffer.append(data)
def found
_
terminator(self):
if self.reading
_
headers:
self.reading
_
headers = False
self.parse
_
headers("".join(self.ibuffer)
self.ibuffer = []
if self.op.upper() == "POST":
clen = self.headers.getheader("content-length")
self.set
_
terminator(int(clen))
else:
self.handling = True
self.set
_
terminator(None)
self.handle
_
request()
elif not self.handling:
self.set
_
terminator(None) # browsers sometimes over-send
self.cgi
_
data = parse(self.headers, "".join(self.ibuffer))
self.handling = True
self.ibuffer = []
self.handle
_
request()
\end{verbatim}
Doc/lib/libasyncore.tex
Dosyayı görüntüle @
b1af86a1
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
handling services.
}
handling services.
}
\moduleauthor
{
Sam Rushing
}{
rushing@nightmare.com
}
\moduleauthor
{
Sam Rushing
}{
rushing@nightmare.com
}
\sectionauthor
{
Christopher Petrilli
}{
petrilli@amber.org
}
\sectionauthor
{
Christopher Petrilli
}{
petrilli@amber.org
}
\sectionauthor
{
Steve Holden
}{
sholden@holdenweb.com
}
% Heavily adapted from original documentation by Sam Rushing.
% Heavily adapted from original documentation by Sam Rushing.
This module provides the basic infrastructure for writing asynchronous
This module provides the basic infrastructure for writing asynchronous
...
@@ -26,35 +27,21 @@ multiple communication channels at once; doing other work while your
...
@@ -26,35 +27,21 @@ multiple communication channels at once; doing other work while your
I/O is taking place in the ``background.'' Although this strategy can
I/O is taking place in the ``background.'' Although this strategy can
seem strange and complex, especially at first, it is in many ways
seem strange and complex, especially at first, it is in many ways
easier to understand and control than multi-threaded programming.
easier to understand and control than multi-threaded programming.
The
module documented her
e solves many of the difficult problems for
The
\module
{
asyncore
}
modul
e solves many of the difficult problems for
you, making the task of building sophisticated high-performance
you, making the task of building sophisticated high-performance
network servers and clients a snap.
network servers and clients a snap. For ``conversational'' applications
and protocols the companion
\refmodule
{
asynchat
}
module is invaluable.
\begin{classdesc}
{
dispatcher
}{}
The basic idea behind both modules is to create one or more network
The first class we will introduce is the
\class
{
dispatcher
}
class.
\emph
{
channels
}
, instances of class
\class
{
asyncore.dispatcher
}
and
This is a thin wrapper around a low-level socket object. To make
\class
{
asynchat.async
_
chat
}
. Creating the channels adds them to a global
it more useful, it has a few methods for event-handling on it.
map, used by the
\function
{
loop()
}
function if you do not provide it
Otherwise, it can be treated as a normal non-blocking socket object
.
with your own
\var
{
map
}
.
The direct interface between the select loop and the socket object
Once the initial channel(s) is(are) created, calling the
\function
{
loop()
}
are the
\method
{
handle
_
read
_
event()
}
and
function activates channel service, which continues until the last
\method
{
handle
_
write
_
event()
}
methods. These are called whenever an
channel (including any that have been added to the map during asynchronous
object `fires' that event.
service) is closed.
The firing of these low-level events can tell us whether certain
higher-level events have taken place, depending on the timing and
the state of the connection. For example, if we have asked for a
socket to connect to another host, we know that the connection has
been made when the socket fires a write event (at this point you
know that you may write to it with the expectation of success).
The implied higher-level events are:
\begin{tableii}
{
l|l
}{
code
}{
Event
}{
Description
}
\lineii
{
handle
_
connect()
}{
Implied by a write event
}
\lineii
{
handle
_
close()
}{
Implied by a read event with no data available
}
\lineii
{
handle
_
accept()
}{
Implied by a read event on a listening socket
}
\end{tableii}
\end{classdesc}
\begin{funcdesc}
{
loop
}{
\optional
{
timeout
\optional
{
, use
_
poll
\optional
{
,
\begin{funcdesc}
{
loop
}{
\optional
{
timeout
\optional
{
, use
_
poll
\optional
{
,
map
}}}}
map
}}}}
...
@@ -64,21 +51,67 @@ network servers and clients a snap.
...
@@ -64,21 +51,67 @@ network servers and clients a snap.
\function
{
select()
}
or
\function
{
poll()
}
call, measured in seconds;
\function
{
select()
}
or
\function
{
poll()
}
call, measured in seconds;
the default is 30 seconds. The
\var
{
use
_
poll
}
parameter, if true,
the default is 30 seconds. The
\var
{
use
_
poll
}
parameter, if true,
indicates that
\function
{
poll()
}
should be used in preference to
indicates that
\function
{
poll()
}
should be used in preference to
\function
{
select()
}
(the default is
false
). The
\var
{
map
}
parameter
\function
{
select()
}
(the default is
\code
{
False
}
). The
\var
{
map
}
parameter
is a dictionary
that gives a list of
channels to watch. As channels
is a dictionary
whose items are the
channels to watch. As channels
are closed they are deleted from their map. If
\var
{
map
}
is
are closed they are deleted from their map. If
\var
{
map
}
is
omitted, a global map is used.
omitted, a global map is used (this map is updated by the default
class
\method
{__
init
__
()
}
-- make sure you extend, rather than override,
\method
{__
init
__
()
}
if you want to retain this behavior).
Channels (instances of
\class
{
asyncore.despatcher
}
,
\class
{
asynchat.async
_
chat
}
and subclasses thereof) can freely be mixed in the map.
\end{funcdesc}
\end{funcdesc}
This set of user-level events is larger than the basics. The
\begin{classdesc}
{
dispatcher
}{}
full set of methods that can be overridden in your subclass are:
The
\class
{
dispatcher
}
class is a thin wrapper around a low-level socket object.
To make it more useful, it has a few methods for event-handling which are called
from the asynchronous loop.
Otherwise, it can be treated as a normal non-blocking socket object.
Two class attributes can be modified, to improve performance,
or possibly even to conserve memory.
\begin{datadesc}
{
ac
_
in
_
buffer
_
size
}
The asynchronous input buffer size (default
\code
{
4096
}
).
\end{datadesc}
\begin{datadesc}
{
ac
_
out
_
buffer
_
size
}
The asynchronous output buffer size (default
\code
{
4096
}
).
\end{datadesc}
The firing of low-level events at certain times or in certain connection
states tells the asynchronous loop that certain higher-level events have
taken place. For example, if we have asked for a socket to connect to
another host, we know that the connection has been made when the socket
becomes writable for the first time (at this point you know that you may
write to it with the expectation of success). The implied higher-level
events are:
\begin{tableii}
{
l|l
}{
code
}{
Event
}{
Description
}
\lineii
{
handle
_
connect()
}{
Implied by the first write event
}
\lineii
{
handle
_
close()
}{
Implied by a read event with no data available
}
\lineii
{
handle
_
accept()
}{
Implied by a read event on a listening socket
}
\end{tableii}
During asynchronous processing, each mapped channel's
\method
{
readable()
}
and
\method
{
writable()
}
methods are used to determine whether the channel's
socket should be added to the list of channels
\cfunction
{
select()
}
ed or
\cfunction
{
poll()
}
ed for read and write events.
\end{classdesc}
Thus, the set of channel events is larger than the basic socket events.
The full set of methods that can be overridden in your subclass follows:
\begin{methoddesc}
{
handle
_
read
}{}
\begin{methoddesc}
{
handle
_
read
}{}
Called when there is new data to be read from a socket.
Called when the asynchronous loop detects that a
\method
{
read()
}
call on the channel's socket will succeed.
\end{methoddesc}
\end{methoddesc}
\begin{methoddesc}
{
handle
_
write
}{}
\begin{methoddesc}
{
handle
_
write
}{}
Called when there is an attempt to write data to the object.
Called when the asynchronous loop detects that a writable socket
can be written.
Often this method will implement the necessary buffering for
Often this method will implement the necessary buffering for
performance. For example:
performance. For example:
...
@@ -96,9 +129,9 @@ def handle_write(self):
...
@@ -96,9 +129,9 @@ def handle_write(self):
\end{methoddesc}
\end{methoddesc}
\begin{methoddesc}
{
handle
_
connect
}{}
\begin{methoddesc}
{
handle
_
connect
}{}
Called when the
socket actually makes a connection. This
Called when the
active opener's socket actually makes a connection.
might be used to send a ``welcome'' banner, or something
Might send a ``welcome'' banner, or initiate a protocol
similar
.
negotiation with the remote endpoint, for example
.
\end{methoddesc}
\end{methoddesc}
\begin{methoddesc}
{
handle
_
close
}{}
\begin{methoddesc}
{
handle
_
close
}{}
...
@@ -111,28 +144,29 @@ def handle_write(self):
...
@@ -111,28 +144,29 @@ def handle_write(self):
\end{methoddesc}
\end{methoddesc}
\begin{methoddesc}
{
handle
_
accept
}{}
\begin{methoddesc}
{
handle
_
accept
}{}
Called on listening sockets when they actually accept a new
Called on listening channels (passive openers) when a
connection.
connection can be established with a new remote endpoint that
has issued a
\method
{
connect()
}
call for the local endpoint.
\end{methoddesc}
\end{methoddesc}
\begin{methoddesc}
{
readable
}{}
\begin{methoddesc}
{
readable
}{}
Each time through the
\method
{
select()
}
loop, the set of sockets
Called each time around the asynchronous loop to determine whether a
is scanned, and this method is called to see if there is any
channel's socket should be added to the list on which read events can
interest in reading. The default method simply returns
\code
{
True
}
,
occur. The default method simply returns
\code
{
True
}
,
indicating that by default, all channels will be interested.
indicating that by default, all channels will be interested in
read events.
\end{methoddesc}
\end{methoddesc}
\begin{methoddesc}
{
writable
}{}
\begin{methoddesc}
{
writable
}{}
Each time through the
\method
{
select()
}
loop, the set of sockets
Called each time around the asynchronous loop to determine whether a
is scanned, and this method is called to see if there is any
channel's socket should be added to the list on which write events can
interest in writing. The default method simply returns
\code
{
True
}
,
occur. The default method simply returns
\code
{
True
}
,
indicating that by default, all channels will be interested.
indicating that by default, all channels will be interested in
write events.
\end{methoddesc}
\end{methoddesc}
In addition, there are the basic methods needed to construct and
In addition, each channel delegates or extends many of the socket methods.
manipulate ``channels,'' which are what we will call the socket
Most of these are nearly identical to their socket partners.
connections in this context. Note that most of these are nearly
identical to their socket partners.
\begin{methoddesc}
{
create
_
socket
}{
family, type
}
\begin{methoddesc}
{
create
_
socket
}{
family, type
}
This is identical to the creation of a normal socket, and
This is identical to the creation of a normal socket, and
...
@@ -144,15 +178,17 @@ identical to their socket partners.
...
@@ -144,15 +178,17 @@ identical to their socket partners.
\begin{methoddesc}
{
connect
}{
address
}
\begin{methoddesc}
{
connect
}{
address
}
As with the normal socket object,
\var
{
address
}
is a
As with the normal socket object,
\var
{
address
}
is a
tuple with the first element the host to connect to, and the
tuple with the first element the host to connect to, and the
second the port.
second the port
number
.
\end{methoddesc}
\end{methoddesc}
\begin{methoddesc}
{
send
}{
data
}
\begin{methoddesc}
{
send
}{
data
}
Send
\var
{
data
}
out
the socket.
Send
\var
{
data
}
to the remote end-point of
the socket.
\end{methoddesc}
\end{methoddesc}
\begin{methoddesc}
{
recv
}{
buffer
_
size
}
\begin{methoddesc}
{
recv
}{
buffer
_
size
}
Read at most
\var
{
buffer
_
size
}
bytes from the socket.
Read at most
\var
{
buffer
_
size
}
bytes from the socket's remote end-point.
An empty string implies that the channel has been closed from the other
end.
\end{methoddesc}
\end{methoddesc}
\begin{methoddesc}
{
listen
}{
backlog
}
\begin{methoddesc}
{
listen
}{
backlog
}
...
@@ -179,13 +215,13 @@ identical to their socket partners.
...
@@ -179,13 +215,13 @@ identical to their socket partners.
\begin{methoddesc}
{
close
}{}
\begin{methoddesc}
{
close
}{}
Close the socket. All future operations on the socket object
Close the socket. All future operations on the socket object
will fail. The remote end will receive no more data (after
will fail. The remote end
-point
will receive no more data (after
queued data is flushed). Sockets are automatically closed
queued data is flushed). Sockets are automatically closed
when they are garbage-collected.
when they are garbage-collected.
\end{methoddesc}
\end{methoddesc}
\subsection
{
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
As a basic example, below is a very basic HTTP client that uses the
\class
{
dispatcher
}
class to implement its socket handling:
\class
{
dispatcher
}
class to implement its socket handling:
...
...
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