def do_echos(): try: client = Client() yield client.connect('localhost', 8000) t = time.time() for x in xrange(10000): msg = "hello, world #%s!" % x yield client.write(msg + '\r\n') echo_result = yield client.read_until("\r\n") assert echo_result.strip() == "you said: %s" % msg print('10000 loops in %.2fs' % (time.time() - t)) finally: client.close()
def test_lots_of_messages(): add_service(Service(handle_echo, port=8000)) try: client = Client() yield client.connect('localhost', 8000) t = time.time() for x in xrange(10000): msg = "hello, world #%s!" % x yield client.write(msg + '\r\n') echo_result = yield client.read_until("\r\n") assert echo_result.strip() == "you said: %s" % msg print '10000 loops in %.2fs' % (time.time() - t) finally: client.close()
def send(dir, coin, to): try: receipt=Send(None, pub, epoch(), coin, loadPublic(to)) receipt.setPrivate(priv) receipt.sign() receipts=Receipts() receipts.load(dir+'/receipts.dat') receipts.add(receipt) smsg=json.dumps(receipt.save(True)) print('sending') client=Client() yield client.connect('localhost', 7050) yield client.write(smsg+"\n") s=yield client.read_until("\n") msg=json.loads(s) receipt=Receive() receipt.load(msg) if receipt.cmd!='receive': print('Unknown command: '+str(receipt.cmd)) return if receipt.args.save_pkcs1('DER')!=pub.save_pkcs1('DER'): print('Not me') return if not rsa.verify(str(receipt.sig), receipt.pub): print('Not verified') return cs.save(dir+'/coins.dat') receipts.add(receipt) print('saving '+str(len(receipts.receipts))) receipts.save(dir+'/receipts.dat') eventloop.halt() except Exception, e: print('Exception:') print(e) traceback.print_exc()