-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.py
More file actions
58 lines (45 loc) · 1.06 KB
/
client.py
File metadata and controls
58 lines (45 loc) · 1.06 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import socket
import time
import select
import sys
s = socket.socket()
print("Enter IP address of server")
host = input()
print("Enter port")
port = input()
s.connect((host, int(port))) # Connect to server
# Receive questions and answer
inst=str(s.recv(1024),"utf-8")
print (inst)
p=int(inst[20:22])
k=0
a=str(s.recv(1024),"utf-8")
print(a)
y=str(s.recv(1024),"utf-8")
print(y)
while (k<=p):
data = str(s.recv(1024),"utf-8")
if data=="Hi":
break
print(data)
c,c1,c2=select.select([sys.stdin,s],[],[],20)
if len(c)>0:
if c[0] == sys.stdin:
y=input()
s.send(str.encode(y))
else:
d=str(c[0].recv(1024),"utf-8")
print (d)
k=k+1
continue;
data2=str(s.recv(1024),"utf-8")
print (data2)
if data2=='Answer the Question':
ans=input()
time.sleep(1)
s.send(str.encode(ans))
k=k+1
rep=str(s.recv(1024),"utf-8")
print(rep)
data3=str(s.recv(1024),"utf-8")
print(data3)