- Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathserver_select.py
More file actions
Latest commit
39 lines (30 loc) · 798 Bytes
/
Copy pathserver_select.py
File metadata and controls
39 lines (30 loc) · 798 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
importselect
importsocket
importsys
HOST=''
PORT=8888
backlog=5
size=1024
server=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind ((HOST, PORT))
server.listen(backlog)
input= [server, sys.stdin]
running=1
whilerunning:
inputready, outputready, exceptready=select.select(input, [],[]) # select dumps in 3
forsininputready:
ifs==server:
client, address=server.accept()
input.append(client)
elifs==sys.stdin:
junk=sys.stdin.readline()
running=0
else:
data=s.recv(size)
ifdata:
printdata
s.send('server: '+data)
else:
s.close()
input.remove(s)
server.close()