-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_sender.py
40 lines (37 loc) · 1.05 KB
/
file_sender.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Usage: python file_sender.py [dummy|ss|gbn] [file_name]
import config
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]
print(os.path)
assert os.path.isfile(file_name)
start_time = time.time()
try:
transport_layer = util.get_transport_layer_by_name(
transport_layer_name,
config.SENDER_LISTEN_PORT,
config.RECEIVER_LISTEN_PORT, 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 ' + str(len(msg)))
while not transport_layer.send(msg):
# Keep retrying to send
pass
except KeyboardInterrupt:
print('bye...')
exit()
finally:
if transport_layer:
transport_layer.shutdown()
end_time = time.time()
print('Time used [secs]:', end_time - start_time)