-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.py
41 lines (36 loc) · 1.54 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
import socket
from config import CONNECTION_STRING, read_data, FORMAT
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as server:
server.connect(CONNECTION_STRING)
name = input("What's your name:")
request = f'HELLO\r\n{name}\r\n\r\n'
server.sendall(request.encode(FORMAT))
response = read_data(server).decode(FORMAT)
if response.split()[0] == "HELLO":
print(response)
while True:
operation = input('What function do you want to use (1-integral, 0-disconnect):')
if operation == "1":
a = input("Bottom Range:")
b = input("Top Range:")
f = input("Function:")
request = f"INTEGRAL\r\nBOTTOM-RANGE: {a}\r\nTOP-RANGE: {b}\r\nFUNCTION: {f}\r\n\r\n"
server.sendall(request.encode(FORMAT))
response = read_data(server).decode(FORMAT)
if response.split()[0] == 'RESULT:':
print(f"server returned: {response.split()[1]}")
else:
print("error occurred")
elif operation == "0":
print("Bye")
server.sendall("BYE\r\n\r\n".encode(FORMAT))
response = read_data(server).decode(FORMAT)
if response == "BYE\r\n\r\n":
break
else:
print("no i się wyjebało")
else:
print("ty jebany przygłupie, czytaj ze zrozumieniem, 1 albo 0")
else:
print('no i się wyjebało')
server.close()