-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
28 lines (24 loc) · 885 Bytes
/
client.py
File metadata and controls
28 lines (24 loc) · 885 Bytes
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
import socket
class Client:
def __init__(self, host="192.168.1.3", port=7777):
self.host = host
self.port = port
def play(self, input_func=input, socket_module=socket):
with socket_module.socket(socket.AF_INET, socket.SOCK_STREAM) as client_socket:
client_socket.connect((self.host, self.port))
print("Connected to the server. Start guessing!")
while True:
guess = input_func("Enter your guess (1-100): ")
client_socket.sendall(guess.encode())
response = client_socket.recv(1024).decode()
print(response)
if response == "Correct! You win!":
break
def main():
client = Client()
try:
client.play()
except KeyboardInterrupt:
print("stopping client")
if __name__ == "__main__":
main()