-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathClient.py
42 lines (35 loc) · 1.59 KB
/
Client.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
import argparse
import RDT
import time
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Quotation client talking to a Pig Latin server.')
parser.add_argument('server', help='Server.')
parser.add_argument('port', help='Port.', type=int)
args = parser.parse_args()
msg_L = [
'The use of COBOL cripples the mind; its teaching should, therefore, be regarded as a criminal offense. -- Edsgar Dijkstra',
'C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg. -- Bjarne Stroustrup',
'A mathematician is a device for turning coffee into theorems. -- Paul Erdos',
'Grove giveth and Gates taketh away. -- Bob Metcalfe on the trend of hardware speedups not being able to keep up with software demands',
'Wise men make proverbs, but fools repeat them. -- Samuel Palmer']
timeout = 2 # send the next message if no response
time_of_last_data = time.time()
rdt = RDT.RDT('client', args.server, args.port)
for msg_S in msg_L:
print('Converting: ' + msg_S)
rdt.rdt_1_0_send(msg_S)
# receive message
msg_S = None
while msg_S is None:
# try to receiver message before timeout
try:
msg_S = rdt.rdt_1_0_receive()
if msg_S is None:
continue
except RDT.RDTException as e:
print(e)
break
# print the result
if msg_S:
print('to: ' + msg_S + '\n')
rdt.disconnect()