-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientTest.py
More file actions
45 lines (33 loc) · 994 Bytes
/
ClientTest.py
File metadata and controls
45 lines (33 loc) · 994 Bytes
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 socket, sys, select
if __name__ == "__main__":
host = socket.gethostname()
port = 12354
s = socket.socket()
try:
s.connect((host, port))
except:
print 'Unable to connect'
sys.exit()
rlist = [sys.stdin, s]
try:
while True:
readList, writeList, errorList = select.select(rList, [], [])
quitProgram = False
for element in readList:
if element == s:
data = s.recv(4096)
if not data:
print "this connection is not available"
else:
print data
else:
data = sys.stdin.readline()
s.send(data)
if data == 'q':
quitProgram = True
break
if quitProgram:
s.close()
break
except:
s.close()