-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathStartClient.py
66 lines (54 loc) · 1.41 KB
/
StartClient.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
53
54
55
56
57
58
59
import Client
import select
PORT = 8765
SERVER_ADDR = ('localhost', PORT)
DELIMITER = "\0"
with open("Genesis.txt") as f:
# retain "\n"
# newline is msg delimiter
MSGS = []
while True:
msg = f.readline()
if msg == "":
break
msg = msg + DELIMITER
MSGS.append(msg)
client = Client.Client(SERVER_ADDR, MSGS) # creates a non-blocking client socket
#rsocket = [client.sock]
wsocket = [client.sock]
rsocket = []
running = True
while running:
print "at top of client select loop", rsocket, wsocket
readready, writeready, _ = select.select(rsocket, wsocket, [])
print readready, writeready
print len(writeready), len(readready)
for s in readready:
isDone = client.receive()
if isDone:
print "{} done receiving recvL".format(s.fileno())
rsocket.remove(s)
running = False
s.close()
else:
print "{} still receiving".format(s.fileno())
if s not in rsocket:
# monitor for reading
rsocket.append(s)
for s in writeready:
isDone = client.send()
if isDone:
print "{} done sending".format(s.fileno())
# no need to monitor this write channel anymore
wsocket = []
# need to monitor read channel for a response
if s not in rsocket:
rsocket.append(s)
else:
print "{} still sending".format(s.fileno())
if s not in rsocket:
# monitor read channel for a response
rsocket.append(s)
print "after client select loop", running
print readready is None
print readready == []