-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathSender.py
55 lines (48 loc) · 1.51 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import sys
import getopt
import Checksum
import BasicSender
'''
This is a skeleton sender class. Create a fantastic transport protocol here.
'''
class Sender(BasicSender.BasicSender):
# Main sending loop.
def start(self):
raise NotImplementedError
'''
This will be run if you run this script from the command line. You should not
change any of this; the grader may rely on the behavior here to test your
submission.
'''
if __name__ == "__main__":
def usage():
print "BEARS-TP Sender"
print "-f FILE | --file=FILE The file to transfer; if empty reads from STDIN"
print "-p PORT | --port=PORT The destination port, defaults to 33122"
print "-a ADDRESS | --address=ADDRESS The receiver address or hostname, defaults to localhost"
print "-d | --debug Print debug messages"
print "-h | --help Print this usage message"
try:
opts, args = getopt.getopt(sys.argv[1:],
"f:p:a:d", ["file=", "port=", "address=", "debug="])
except:
usage()
exit()
port = 33122
dest = "localhost"
filename = None
debug = False
for o,a in opts:
if o in ("-f", "--file="):
filename = a
elif o in ("-p", "--port="):
port = int(a)
elif o in ("-a", "--address="):
dest = a
elif o in ("-d", "--debug="):
debug = True
s = Sender(dest,port,filename,debug)
try:
s.start()
except (KeyboardInterrupt, SystemExit):
exit()