import time import util def msg_handler(file_handle, msg): file_handle.write(msg.encode()) if __name__ == '__main__': if len(sys.argv) != 3: print('Usage: python file_receiver.py [dummy|ss|gbn] [file_name]') sys.exit(1) transport_layer = None transport_layer_name = sys.argv[1] file_name = sys.argv[2] assert not os.path.exists(file_name) file_handle = None try: file_handle = open(file_name, 'wb') transport_layer = util.get_transport_layer( 'receiver', transport_layer_name, functools.partial(msg_handler, file_handle)) while True: time.sleep(1) finally: if file_handle: file_handle.close() if transport_layer: transport_layer.shutdown()
import os.path import sys import time import util if __name__ == '__main__': if len(sys.argv) != 3: print('Usage: python file_sender.py [dummy|ss|gbn] [file_name]') sys.exit(1) transport_layer = None transport_layer_name = sys.argv[1] file_name = sys.argv[2] assert os.path.isfile(file_name) start_time = time.time() try: transport_layer = util.get_transport_layer('sender', transport_layer_name, None) with open(file_name, 'rb') as f: while True: msg = f.read(config.MAX_MESSAGE_SIZE) if not msg: break print('MSG of length ', len(msg)) while not transport_layer.send(msg): pass finally: if transport_layer: transport_layer.shutdown() end_time = time.time() print('Time used [secs]:', end_time - start_time)
# Usage: python demo_receiver.py [dummy|ss|gbn] import config import sys import time import util def msg_handler(msg): print(repr(msg)) if __name__ == '__main__': if len(sys.argv) != 2: print('Usage: python demo_receiver.py [dummy|ss|gbn]') sys.exit(1) transport_layer = None transport_layer_name = sys.argv[1] try: transport_layer = util.get_transport_layer('receiver', transport_layer_name, msg_handler) while True: time.sleep(1) finally: if transport_layer: transport_layer.shutdown()
# Usage: python demo_sender.py [dummy|ss|gbn] import config import sys import time import util if __name__ == '__main__': if len(sys.argv) != 2: print('Usage: python demo_sender.py [dummy|ss|gbn]') sys.exit(1) transport_layer = None name = sys.argv[1] start_time = time.time() try: transport_layer = util.get_transport_layer( name, config.SENDER_PORT, config.RECEIVER_PORT, None) for i in range(20): msg = 'MSG:' + str(i) print(msg) while not transport_layer.send(str.encode(msg)): pass finally: if transport_layer: transport_layer.shutdown() end_time = time.time() print('Time used [secs]:', end_time - start_time)
# Usage: python demo_receiver.py [dummy|ss|gbn] import config import sys import time import util def msg_handler(msg): print(repr(msg)) if __name__ == '__main__': if len(sys.argv) != 2: print('Usage: python demo_receiver.py [dummy|ss|gbn]') sys.exit(1) transport_layer = None transport_layer_name = sys.argv[1] try: transport_layer = util.get_transport_layer('receiver', transport_layer_name, msg_handler) # instantiate a transport layer protocol while True: time.sleep(1) finally: if transport_layer: transport_layer.shutdown()
# Usage: python demo_receiver.py [dummy|ss|gbn] import config import sys import time import util def msg_handler(msg): print(repr(msg)) if __name__ == '__main__': if len(sys.argv) != 2: print('Usage: python demo_receiver.py [dummy|ss|gbn]') sys.exit(1) transport_layer = None name = sys.argv[1] try: transport_layer = util.get_transport_layer(name, config.RECEIVER_PORT, config.SENDER_PORT, msg_handler) while True: time.sleep(1) finally: if transport_layer: transport_layer.shutdown()