asynchat question

Discussion in 'Python' started by Patrick Useldinger, Aug 17, 2003.

  1. I am trying to write both a server and a client using asynchat.
    For both, I have created a common subclass to collect the incoming data:

    class SingleServer(asynchat.async_chat):
    def __init__(self,*args):
    asynchat.async_chat.__init__(self,*args)
    self.set_terminator(BLOCKEND)
    self.data=[]
    def collect_incoming_data(self,data):
    self.data.append(data)
    def found_terminator(self):
    self.processData(''.join(self.data))
    self.data=[]

    The server works well, it waits for a connection and sends a response.

    class SecondaryServer(SingleServer):
    def processData(self,data):
    response='??'
    peer=self.getpeername()
    print now(),'from %s received %s' % (peer,repr(data))
    if data == 'quit':
    if peer[0]=='127.0.0.1':
    response='OK'
    dispatcher.close()
    else:
    response='KO'
    response=response+' '+data
    print now(),'to %s responding %s' % (peer,repr(response))
    self.push(response+BLOCKEND)

    However, I am having trouble with the client, who is supposed to send a
    question and get an answer in return:

    class Server(SingleServer):
    def __init__(self,message,*args):
    SingleServer.__init__(self,*args)
    print now(),'connecting to EB on %s:%s' % (EBHost,EBPort)
    self.create_socket(socket.AF_INET,socket.SOCK_STREAM)
    self.connect((EBHost,EBPort))
    def handle_connect(self):
    print now(),'sending %s' % repr(message)
    self.push(message+BLOCKEND)
    def processData(self,data):
    print now(),'received "%s"' % repr(response)
    self.close() # XXX is socket closed by base class?

    Server(message)

    The client connects and send his question. The server answers, but the
    client never receives an answer. On the server side, I receive the
    following message:

    error: uncaptured python exception, closing channel
    __main__.SecondaryServer connected 127.0.0.1:3432 at 0x7fc968>
    (socket.error:(10053, 'Software caused connection abort')
    C:\Python23\lib\asynchat.py|handle_read|88] [C:\Python23\lib\asyn
    core.py|recv|353])

    Can anyone explain why?

    --
    Real e-mail address is 'cHVAdm8ubHU=\n'.decode('base64')
    Visit my Homepage at http://www.homepages.lu/pu/
    Patrick Useldinger, Aug 17, 2003
    #1
    1. Advertising

  2. Sorry, my mistake.
    The behaviour is actually that for the client, handle_connect() is never
    called, so the message is never send.

    Why?

    --
    Real e-mail address is 'cHVAdm8ubHU=\n'.decode('base64')
    Visit my Homepage at http://www.homepages.lu/pu/
    Patrick Useldinger, Aug 17, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Welsh

    asyncore asynchat

    Michael Welsh, Jul 15, 2003, in forum: Python
    Replies:
    0
    Views:
    515
    Michael Welsh
    Jul 15, 2003
  2. F.G.Testa

    asyncore/asynchat

    F.G.Testa, Nov 14, 2003, in forum: Python
    Replies:
    4
    Views:
    426
    MetalOne
    Nov 17, 2003
  3. Joshua Moore-Oliva

    asyncore, asynchat and threads

    Joshua Moore-Oliva, Aug 4, 2004, in forum: Python
    Replies:
    4
    Views:
    1,054
    Joshua Moore-Oliva
    Aug 4, 2004
  4. Josh Close

    asynchat connection timeout

    Josh Close, Aug 26, 2004, in forum: Python
    Replies:
    1
    Views:
    337
    Brian Gough
    Aug 27, 2004
  5. Rob Snyder

    asynchat and threading

    Rob Snyder, Nov 24, 2004, in forum: Python
    Replies:
    16
    Views:
    776
    Fredrik Lundh
    Dec 6, 2004
Loading...

Share This Page