-
Notifications
You must be signed in to change notification settings - Fork 0
/
finalProjectClient.py
52 lines (37 loc) · 1.13 KB
/
finalProjectClient.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
46
47
48
49
50
51
52
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 7 11:07:21 2018
@author: diazrodrigueza
"""
import json
import socket
import sys
servername = 'localhost'
serverport = 9999
clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
clientsocket.connect((servername, serverport))
message = clientsocket.recv(1024).decode()
print(message)
clientresponse = input()
clientsocket.send(clientresponse.encode())
message = clientsocket.recv(1024).decode()
print(message)
data = {'h':0, 'b':''}
guesses = []
while clientresponse != 'exit':
clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
clientsocket.connect((servername, serverport))
#prints guess 4 colors
serverresponse = clientsocket.recv(1024).decode()
print(serverresponse)
guesses.clear()
while len(guesses)<4:
guesses.append(input())
data['h'] = data['h']+1
data['b'] = guesses
clientsocket.send(json.dumps(data).encode())
message = clientsocket.recv(1024).decode()
print(message)
if message==('You won!'):
break
clientsocket.close()