def _send(self, packet, buffer=False): packet.ack_num = self.recv_window.confirmed if not buffer: print_info(self.name, 'sending', packet) self.socket.send(packet.encode()) else: packet = self.send_window.put_packet(packet) print_info(self.name, 'buffered', packet)
def two_ends(): from adaptors import DropoutSocket, CorruptedSocket, DisorderSocket server = threading.Thread(target=start_server, args=()) server.setDaemon(True) server.start() client_protocol = start_client(lambda x: DisorderSocket(0.5, x)) client_protocol.send(b'hello, world1') client_protocol.send(b'hello, world2') client_protocol.send(b'hello, world3') client_protocol.send(b'hello, world4') client_protocol.flush() client_protocol.close() print_info('done')
def start_server(): global print_count server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) server.setblocking(False) server.bind(('0.0.0.0', SERVER_PORT)) server.connect((CLIENT_IP, CLIENT_PORT)) server_protocol = Protocol(server, name='server') while server_protocol.open: with endpoint_mutex: print_info("Server round") packet = server_protocol.recv() if packet: print_info('Server', packet) print_count += 1 time.sleep(yield_time)
def _recv(self): if not self.open: raise ConnectionResetError('Connection reset') try: data = self.socket.recv(8192) except IOError as ex: if ex.errno == 11: return raise ex if not data: return packet = Packet().decode(data) if packet.chk_sum != packet.compute_checksum(): print_info(self.name, 'Checksum error, discarding', packet) return print_info(self.name, 'received', packet) return packet
def recv(self, bufsize=8192): packet = self.socket.recv(bufsize) print_info(self, 'recv', packet) return packet
def send(self, data): print_info('Writing data', data)
def test_byte_buf(): buf = ByteBuf() buf.write_int(666) print_info(buf.read_int()) buf.write_data(b'hello, world') print_info(buf.read_data())
# ----------------------------------------------------------------------------- # From Numpy to Python # Copyright (2017) Nicolas P. Rougier - BSD license # More information at https://github.com/rougier/numpy-book # ----------------------------------------------------------------------------- import numpy as np from tools import print_info if __name__ == '__main__': Z = np.arange(5 * 5).reshape(5, 5) print_info(Z) # Z = np.array(Z,order='F') # info(Z)