File: nc_server.py

package info (click to toggle)
libnginx-mod-http-lua 1%3A0.10.28-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,456 kB
  • sloc: ansic: 42,658; perl: 480; sh: 303; python: 23; makefile: 11
file content (25 lines) | stat: -rw-r--r-- 665 bytes parent folder | download | duplicates (2)
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
import select, socket
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.setblocking(0)
server.bind(('localhost', 65110))
server.listen(5)
inputs = [server]

while inputs:
    outputs = []
    readable, writable, exceptional = select.select(
        inputs, outputs, inputs)
    for s in readable:
        if s is server:
            connection, client_address = s.accept()
            connection.setblocking(0)
            inputs.append(connection)
        else:
            data = s.recv(1024)
            if not data:
                inputs.remove(s)
                s.close()

    for s in exceptional:
        inputs.remove(s)
        s.close()