-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient2.py
More file actions
40 lines (32 loc) · 1.07 KB
/
client2.py
File metadata and controls
40 lines (32 loc) · 1.07 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
import socket
from buz_first import *
from datetime import datetime
from ans_time import *
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(('0.0.0.0', 8080))
while True:
from_server = client.recv(4096)
#Game termination when "U Lost" or "U Won" is received
if(from_server[0] == "U"):
break
print from_server
#To calculate the time taken by client to press the buzzer
#Sending the time taken to server
#Server receives time taken from three clients
#and decides upon whom to chose for answering
now = datetime.now()
before_time = now.strftime("%S")
if (type(from_server) == str):
buzz = buzzer(0)
ans_in = buz_first(before_time,buzz)
client.send(str(ans_in))
#Command to type/wait forothers to type in the answer
from_server = client.recv(4096)
print from_server
#If the command is to "Type the answer"
#Then sending the answer
if (from_server[0]=='T'):
answer = buzzer(1)
client.send(answer)
client.close()
print from_server