forked from flypythoncom/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpollclient.py
More file actions
47 lines (37 loc) · 908 Bytes
/
pollclient.py
File metadata and controls
47 lines (37 loc) · 908 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
44
45
#!/usr/bin env python
import socket,sys,select
port=8888
host='localhost'
spinsize=10
spinpos=0
spindir=1
def spin():
global spinsize,spinpos,spindir
spinstr='.' * spinpos + '|'+'.'(spinsize-spinpos-1)
sys.stdout.write('r'+ spinstr + ' ')
sys.stdout.flush()
spinpos += spindir
if spinpos < 0:
spindir=1
spinpos=1
elif spinpos >= spinsize:
spinpos -= 2
spindir = -1
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((host,port))
p=select.poll()
p.register(s.fileno(),select.POLLIN | select.POLLERR | select.POLLHUP)
while 1:
results=p.poll(50)
if len(results):
if results[0][1] == select.POLLIN:
data = s.recv(4096)
if not len(data):
print "Remote end closed connect"
break
sys.stdout.write("\rReceived:" + data)
sys.stdout.flush()
else:
print "\rproblem occurred ; exiting"
sys.exit(0)
spin()