- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
Latest commit
53 lines (41 loc) · 1.26 KB
/
Copy pathclient.py
File metadata and controls
53 lines (41 loc) · 1.26 KB
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
# Client
importquery_struct
importsocket
importpickle
HOST="127.0.0.1"
PORT=55557
MAX_DATA_SIZE=65536
CLIENT_PROMPT="$ my_client "
deffibo_query(index,server_socket):
"""
sends a query to compute fibo(index)
"""
server_socket.send(pickle.dumps(query_struct.Query(query_struct.Query_type.COMPUTE_FIBO, value=index)))
deflist_query(server_socket):
"""
sends a query to get the list of computations
"""
server_socket.send(pickle.dumps(query_struct.Query(query_struct.Query_type.LIST)))
forqueryinpickle.loads(server_socket.recv(MAX_DATA_SIZE)):
print(query)
defexec_query(server_socket):
"""
gets a command, parses it and send the appropriate qury to the server
"""
request=input(CLIENT_PROMPT).split()
iflen(request) ==2andrequest[0] =="send":
try:
index=int(request[1])
except:
print(request[1] +" : not a valid number")
else:
fibo_query(index,server_socket)
iflen(request) ==1andrequest[0] =="list":
list_query(server_socket)
defmain():
server_socket=socket.socket()
server_socket.connect((HOST, PORT))
whileTrue:
exec_query(server_socket)
if__name__=="__main__":
main()