- Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathnc_server.py
25 lines (23 loc) · 665 Bytes
/
nc_server.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
importselect, socket
server=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.setblocking(0)
server.bind(('localhost', 65110))
server.listen(5)
inputs= [server]
whileinputs:
outputs= []
readable, writable, exceptional=select.select(
inputs, outputs, inputs)
forsinreadable:
ifsisserver:
connection, client_address=s.accept()
connection.setblocking(0)
inputs.append(connection)
else:
data=s.recv(1024)
ifnotdata:
inputs.remove(s)
s.close()
forsinexceptional:
inputs.remove(s)
s.close()