asynchat question

P

Patrick Useldinger

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?
 
P

Patrick Useldinger

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

Why?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top