-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.py
More file actions
43 lines (33 loc) · 1.16 KB
/
Client.py
File metadata and controls
43 lines (33 loc) · 1.16 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
import socket
class GuessingGameClient:
def __init__(self, host="192.168.254.105", port=7777):
self.host = host
self.port = port
def play(self):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as client_socket:
client_socket.connect((self.host, self.port))
prompt = client_socket.recv(1024).decode()
print(prompt, end='')
password = input()
client_socket.sendall(password.encode())
response = client_socket.recv(1024).decode()
print(response)
if "Incorrect" in response:
return
while True:
guess = input("Enter your guess (1-100): ")
client_socket.sendall(guess.encode())
response = client_socket.recv(1024).decode()
print(response)
if "Correct!" in response:
break
def main():
client = GuessingGameClient()
try:
client.play()
except KeyboardInterrupt:
print("Stopping client")
finally:
pass
if __name__ == "__main__":
main()