[Tutor] doubts with socket asychronous doc..,

Ajaya Babu ajaya@ncoretech.com
Wed, 12 Sep 2001 19:01:58 +0530


Hi,

I've some dbouts of using asyncore module for asychronous socket service
clients and servers.

http://www.python.org/doc/current/lib/module-asyncore.html



Example is given like this


class http_client(asyncore.dispatcher):
    def __init__(self, host,path):
        asyncore.dispatcher.__init__(self)
        self.path = path
        self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
        self.connect( (host, 80) )
        self.buffer = 'GET %s HTTP/1.0\r\n\r\n' % self.path

    def handle_connect(self):
        pass

    def handle_read(self):
        data = self.recv(8192)
        print data

    def writable(self):
        return (len(self.buffer) > 0)

    def handle_write(self):
        sent = self.send(self.buffer)
        self.buffer = self.buffer[sent:]


from the documentation I understand handle_read will be called when ever new
data to be read from the socket..., and handle_write will be called when
attempt to write the object.

but I did not understand these terms properly. I had a confustion who is
going to initiate these events. Like read or write....,

For example my C server send some data on port x, suppose my python
appliation should recive that data as a asynchronous menas is this just ok
if I make a instant of the above class and connect to the
server...,(Assuming that handle_read) will be called asynchronously when
data arives to that port.

but Documentation is telling me it is wraper around the select() fuction.
Generally select() function need to be polled as my understanding. It just
gives the idea that can performing certain action is worth or not..., but
from the above example it is nor clear that who is polling  on this function
to call handle_read functions.

One more thing is if I want to send some data to my C host again.., How do I
do it. Do I need to send just like mysocket.send(buffer)...or handle_write()
how can I use.., it is not clear from the documentation

May be my understanding is poor....since I just started learning python..,
Please send me some doc liks or give  me suggestion to make my study
progress,

Thanks allot  for great help.

with regards,
Ajaya