import asyncore, socket class ProtocolFactory(asyncore.dispatcher): def __init__(self, (protocol, port), multiplexer): asyncore.dispatcher.__init__(self) self.protocol = protocol self.multiplexer = multiplexer self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.bind(("", port)) self.listen(5) def handle_accept(self): # this is called by the asyncore library whenever a # connection has been established conn, addr = self.accept() # spawn a client class self.protocol(conn, self.multiplexer)