forked from kayartaya-vinod/2018_08_PHILIPS_ADV_PYTHON
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex09-client.py
45 lines (33 loc) · 863 Bytes
/
ex09-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
43
44
45
import socket
import pickle
def main():
client = socket.socket()
addr = ('localhost', 9090)
client.connect(addr)
while True:
print('1 - Factorial')
print('2 - Fibonacii')
print('3 - Quit')
choice = int(input('Enter your choice: '))
if choice<1 || choice>3:
print('Invalid input. Please try again!')
continue
request = {}
if choice==3:
request['function_name'] = 'quit'
request = pickle.dumps(request)
client.send(request)
break
num = int(input('Enter a number: '))
request['args'] = [num]
if choice==1:
request['function_name'] = 'factorial'
elif choice==2:
request['function_name'] = 'fibo'
request = pickle.dumps(request)
client.send(request)
response = client.recv(1024)
response = pickle.loads(response)
print('Response from server:', response)
if __name__ == '__main__':
main()