-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
44 lines (37 loc) · 1.15 KB
/
server.py
File metadata and controls
44 lines (37 loc) · 1.15 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 time
import socket
import improved
import os
import struct
import subprocess
# creating a socket object
s = socket.socket(socket.AF_INET,
socket.SOCK_STREAM)
# get local Host machine name
host = ''
port = 6963
obj_dir = './example_objects'
# bind to pot
s.bind((host, port))
# Que up to 5 requests
s.listen(5)
while True:
# establish connection
clientSocket, addr = s.accept()
print("got a connection from %s" % str(addr))
#print(os.popen('lsof -i:{} | cut -f 3 -d" " | grep -v "^$"'.format(addr[1])).read())
word = improved.pick_subject(obj_dir)
print("getting them to guess a", word)
filenames = improved.get_image_filenames(word, obj_dir)
for f in filenames:
ascii_art = improved.colour_ascii(f)
clientSocket.send(ascii_art.encode("utf-8"))
clientSocket.send(b"What is this object?\n")
guess = clientSocket.recv(1024).decode('utf-8').strip()
print("their guess:", guess)
if improved.correct_word(guess, word):
clientSocket.send(b"Wow, well done!\n")
break
else:
clientSocket.send(b"unlucky...\n")
clientSocket.close()