import asyncore import sys DATA = b'X' * 1024 * 1024 class Client(asyncore.dispatcher_with_send): def __init__(self, host, port): asyncore.dispatcher_with_send.__init__(self) self.create_socket() self.connect((host, port)) def handle_connect(self): self.send(DATA) def handle_read(self): print(self.recv(8192)) def handle_write(self): asyncore.dispatcher_with_send.handle_write(self) if not self.out_buffer: self.close() client = Client(sys.argv[1], int(sys.argv[2])) asyncore.loop()