#! /usr/bin/env python3 import sys,os,socket,time,select connsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0) connsock.bind(("",8801)) connsock.listen(5) nb_open = 0 # Create list of potential readers and place connection socket in # first position potential_readers = [connsock] first = True while first or nb_open > 0: first = False readers,_,_ = select.select(potential_readers,[],[],60) for sock_ready in readers: if sock_ready == connsock: conn,(addr,port) = connsock.accept() potential_readers.append(conn) print("Incoming connexion from %s on port %d..."%(addr,port)) input("Appuyer sur entree...") nb_open+=1 else: msg=sock_ready.recv(1024) if (len(msg) == 0): print("NULL message. Closing connection...") sock_ready.close() # Remove the closed connection from potential readers potential_readers.remove(sock_ready) nb_open -= 1 else: os.write(1,msg) connsock.close() print("last connection closed. Bye!") sys.exit(0)