asynchat question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Patrick Useldinger

    asynchat question

    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(as ynchat.async_ch at):
    def __init__(self,* args):
    asynchat.async_ chat.__init__(s elf,*args)
    self.set_termin ator(BLOCKEND)
    self.data=[]
    def collect_incomin g_data(self,dat a):
    self.data.appen d(data)
    def found_terminato r(self):
    self.processDat a(''.join(self. data))
    self.data=[]

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

    class SecondaryServer (SingleServer):
    def processData(sel f,data):
    response='??'
    peer=self.getpe ername()
    print now(),'from %s received %s' % (peer,repr(data ))
    if data == 'quit':
    if peer[0]=='127.0.0.1':
    response='OK'
    dispatcher.clos e()
    else:
    response='KO'
    response=respon se+' '+data
    print now(),'to %s responding %s' % (peer,repr(resp onse))
    self.push(respo nse+BLOCKEND)

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

    class Server(SingleSe rver):
    def __init__(self,m essage,*args):
    SingleServer.__ init__(self,*ar gs)
    print now(),'connecti ng to EB on %s:%s' % (EBHost,EBPort)
    self.create_soc ket(socket.AF_I NET,socket.SOCK _STREAM)
    self.connect((E BHost,EBPort))
    def handle_connect( self):
    print now(),'sending %s' % repr(message)
    self.push(messa ge+BLOCKEND)
    def processData(sel f,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__.Second aryServer connected 127.0.0.1:3432 at 0x7fc968>
    (socket.error:( 10053, 'Software caused connection abort')
    C:\Python23\lib \asynchat.py|ha ndle_read|88] [C:\Python23\lib \asyn
    core.py|recv|35 3])

    Can anyone explain why?

    --
    Real e-mail address is 'cHVAdm8ubHU=\n '.decode('base6 4')
    Visit my Homepage at http://www.homepages.lu/pu/

  • Patrick Useldinger

    #2
    Re: asynchat question

    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('base6 4')
    Visit my Homepage at http://www.homepages.lu/pu/

    Comment

    Working...