Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > asynchat question

Reply
Thread Tools

asynchat question

 
 
Patrick Useldinger
Guest
Posts: n/a
 
      08-16-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_STRE AM)
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.error10053, '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/

 
Reply With Quote
 
 
 
 
Patrick Useldinger
Guest
Posts: n/a
 
      08-16-2003
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/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
asynchat and threading Rob Snyder Python 16 12-06-2004 05:57 PM
asynchat connection timeout Josh Close Python 1 08-27-2004 08:56 AM
asyncore, asynchat and threads Joshua Moore-Oliva Python 4 08-04-2004 05:36 PM
asyncore/asynchat F.G.Testa Python 4 11-17-2003 09:53 PM
asyncore asynchat Michael Welsh Python 0 07-15-2003 11:32 AM



Advertisments