def main(): options, args = parseArgs() fmt='[%(asctime)s][%(levelname)8s] %(message)s' logging.basicConfig(level=options.logging, format=fmt) logging.info('options: %s' % options) logging.info('Starting BsonNetwork Echoer v%s on port %d' \ % (__version__, options.port)) factory = BsonNetworkFactory(options.clientid, options) factory.logging = logging factory.protocol = BsonNetworkEchoProtocol from base import Server server = Server(('', options.port), factory) server.serve_forever()
def testFactory(factory, data, clients=100): '''Tests the given factory with the given data packets.''' from base import Server port = process.randomPort() print 'Starting', factory, 'with', factory.protocol, 'on port', port server = Server(('', port), factory) server.serve() jobs = [] for c in range(0, clients): jobs.append(gevent.spawn(testSendData, data, port)) gevent.joinall(jobs, timeout=15) vals = [(1 if job.value else 0) for job in jobs] print sum(vals), '/', len(vals), 'succeeded' return sum(vals) * 1.0 / len(vals)
def main(): options, args = parseArgs() fmt='[%(asctime)s][%(levelname)8s][' + options.clientid + '] %(message)s' logging.basicConfig(level=options.logging, format=fmt) logging.info('options: %s' % options) logging.info('Starting BsonNetwork Router v%s on port %d' \ % (__version__, options.port)) factory = BsonRouterFactory(options.clientid, options) factory.logging = logging if options.connect_to: logging.info('Starting clients') from base import Client clients = [Client.spawn(factory, addr) for addr in options.connect_to] logging.info('Starting server') from base import Server server = Server(('', options.port), factory) server.serve_forever()
def handle(self): """ Called by super """ logger.info('Serving Request from %s:%s' % self.client_address) session = self.server.session_maker() try: server_id = int(self.rfile.readline().strip()) server = Server.by_id(server_id, session) with open(server.request.path, 'rb') as data: for chunk in iter(lambda: data.read(2 ** 14), b''): self.request.sendall(chunk) except Exception as e: logger.exception(e) finally: session.close() self.request.close()