def send_test(pkg_size=10): self.server = listen(self.address) self.server_con = accept(self.server) initial_data = data = b"123456789a123456789b123456789c123456789d123456789e123456789f123456789g" size = pkg_size while data: pkg, data = data[:size], data[size:] len_send = send(self.server_con, pkg) data = pkg[len_send:] + data close(self.server_con) return initial_data
def send_test(): self.server = listen(self.address) self.server_con = accept(self.server) data = initial_data size = 1024 while data: pkg, data = data[:size], data[size:] len_send = send(self.server_con, pkg) data = pkg[len_send:] + data close(self.server_con) return initial_data
def send_test(pkg_size=1024 * 1024): self.server = listen(self.address) self.server_con = accept(self.server) size = pkg_size with open(server_file, 'rb') as f: read = f.read(size) while read: len_send = send(self.server_con, read) read = f.read(size) close(self.server_con) return ut.file_hash(server_file)
def send_test(pkg_sent_size=10, pkg_rcv_size=10): self.server = listen(self.address) self.server_con = accept(self.server) data = initial_data size = pkg_sent_size while data: pkg, data = data[:size], data[size:] len_send = send(self.server_con, pkg) data = pkg[len_send:] + data send(self.server_con, b"") data = b'' rcv_data = True while rcv_data: rcv_data = recv(self.server_con, pkg_rcv_size) data += rcv_data if len(data) == len(initial_data): break return initial_data, data
def rcv_test(pkg_sent_size=10, pkg_rcv_size=10): self.client_con = dial(self.address) data = initial_data size = pkg_sent_size while data: pkg, data = data[:size], data[size:] len_send = send(self.client_con, pkg) data = pkg[len_send:] + data data = b'' rcv_data = True while rcv_data: rcv_data = recv(self.client_con, pkg_rcv_size) data += rcv_data if len(data) == len(initial_data): break return initial_data, data
def handle(conn, file_path, chunk_size): for chunk in chunked_file(file_path, chunk_size): send(conn, chunk) close(conn)