asynchat question

Patrick Useldinger pu
Sun Aug 17 01:15:13 CEST 2003


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/





More information about the Python-list mailing list