asynchat question

Patrick Useldinger pu
Sun Aug 17 09:46:23 CEST 2003


Erik Max Francis wrote:
> There are several problems here.  For starters, your server class isn't
> really a server, since it doesn't derive from asyncore.dispatcher, and
> doesn't bind to a port, so connections never come in.  (And you wanted
> to override handle_accept, not handle_connect.)  Try something like this
> for your server:

Eric, my problem is with the client. The server is working correctly, I 
only posted the part of the code I thought was relevant for my 
particular problem. The full code is here:

from sasUtils import now,SingleServer
from sasParms import EBPort,BLOCKEND
import asyncore,socket

class Dispatcher(asyncore.dispatcher):
     def __init__(self,port):
         asyncore.dispatcher.__init__(self)
         self.create_socket(socket.AF_INET,socket.SOCK_STREAM)
         self.bind(('',port))
         print now(),'listening to port',port
         self.listen(5)
     def handle_accept(self):
         newSocket, address=self.accept()
         print 'connected from',address
         SecondaryServer(newSocket)

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)

if __name__ == '__main__':
     print now(),'start sasEM'
     dispatcher=Dispatcher(EBPort)
     asyncore.loop()
     print now(),'end sasEM'


Cheers,
-Patrick

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